invalidate sessions before login
This commit is contained in:
parent
7ee95962e1
commit
65b3561244
|
@ -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 })
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue