invalidate sessions before login

This commit is contained in:
Maurits Lourens 2022-03-29 10:06:54 +02:00
parent 7ee95962e1
commit 65b3561244
2 changed files with 14 additions and 2 deletions

View File

@ -5,7 +5,10 @@ const env = require("../../environment")
const { getGlobalUserByEmail } = require("../../utils") const { getGlobalUserByEmail } = require("../../utils")
const { authError } = require("./utils") const { authError } = require("./utils")
const { newid } = require("../../hashing") const { newid } = require("../../hashing")
const { createASession } = require("../../security/sessions") const {
createASession,
invalidateSessions,
} = require("../../security/sessions")
const { getTenantId } = require("../../tenancy") const { getTenantId } = require("../../tenancy")
const INVALID_ERR = "Invalid credentials" const INVALID_ERR = "Invalid credentials"
@ -53,6 +56,9 @@ exports.authenticate = async function (ctx, email, password, done) {
// authenticate // authenticate
if (await compare(password, dbUser.password)) { if (await compare(password, dbUser.password)) {
// invalidate all other sessions
await invalidateSessions(dbUser._id)
const sessionId = newid() const sessionId = newid()
const tenantId = getTenantId() const tenantId = getTenantId()
await createASession(dbUser._id, { sessionId, tenantId }) await createASession(dbUser._id, { sessionId, tenantId })

View File

@ -4,7 +4,10 @@ const { generateGlobalUserID } = require("../../db/utils")
const { saveUser } = require("../../utils") const { saveUser } = require("../../utils")
const { authError } = require("./utils") const { authError } = require("./utils")
const { newid } = require("../../hashing") const { newid } = require("../../hashing")
const { createASession } = require("../../security/sessions") const {
createASession,
invalidateSessions,
} = require("../../security/sessions")
const { getGlobalUserByEmail } = require("../../utils") const { getGlobalUserByEmail } = require("../../utils")
const { getGlobalDB, getTenantId } = require("../../tenancy") const { getGlobalDB, getTenantId } = require("../../tenancy")
const fetch = require("node-fetch") const fetch = require("node-fetch")
@ -76,6 +79,9 @@ exports.authenticateThirdParty = async function (
// never prompt for password reset // never prompt for password reset
dbUser.forceResetPassword = false dbUser.forceResetPassword = false
// invalidate all other sessions
await invalidateSessions(dbUser._id)
// create or sync the user // create or sync the user
let response let response
try { try {