Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.addColumn(
'Users',
'lastActiveAt',
{
type: Sequelize.DATE,
allowNull: true
},
{ transaction }
)

await queryInterface.addIndex('Users', ['lastActiveAt'], {
transaction,
name: 'idx_users_lastActiveAt'
})
})
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.removeIndex('Users', 'idx_users_lastActiveAt', {
transaction
})
await queryInterface.removeColumn('Users', 'lastActiveAt', {
transaction
})
})
}
}
8 changes: 8 additions & 0 deletions packages/identity-service/src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.DATE,
allowNull: false
},
// Touched on every app open via the authenticated startup ping
// (GET /user/email). Used for inactivity detection — finer-grained
// and lazier than lastSeenDate, which only moves at user creation
// and on relay.
lastActiveAt: {
type: DataTypes.DATE,
allowNull: true
},
isGuest: {
type: DataTypes.BOOLEAN,
allowNull: false,
Expand Down
13 changes: 12 additions & 1 deletion packages/identity-service/src/routes/idSignals.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ module.exports = function (app) {
'/record_ip',
authMiddleware,
handleResponse(async (req) => {
const { blockchainUserId, handle } = req.user
const { id: userRowId, blockchainUserId, handle } = req.user

// Fired by the client's recordIPIfNotRecent saga on app open
// (throttled to once per 24h per device), so this is also our
// signal that the user is active. Fire-and-forget — never block
// the IP-record response on this side effect.
models.User.update(
{ lastActiveAt: new Date() },
{ where: { id: userRowId } }
).catch((err) => {
req.logger.error({ err }, 'Failed to update lastActiveAt')
})

try {
const userIP = getIP(req)
Expand Down
4 changes: 3 additions & 1 deletion packages/identity-service/src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ module.exports = function (app) {

try {
const isDeliverable = await isEmailDeliverable(email, req.logger)
const now = new Date()
await models.User.create({
email,
// Store non checksummed wallet address
walletAddress: body.walletAddress.toLowerCase(),
lastSeenDate: Date.now(),
lastSeenDate: now,
lastActiveAt: now,
IP,
isEmailDeliverable: isDeliverable,
isGuest: body.isGuest
Expand Down
Loading