diff --git a/packages/backend-core/src/auth/auth.ts b/packages/backend-core/src/auth/auth.ts index 982b5cfa89..4bdf0e0cd3 100644 --- a/packages/backend-core/src/auth/auth.ts +++ b/packages/backend-core/src/auth/auth.ts @@ -225,7 +225,12 @@ export async function platformLogout(opts: PlatformLogoutOpts) { const sessionIds = sessions.map(({ sessionId }) => sessionId) await invalidateSessions(userId, { sessionIds, reason: "logout" }) - const user = await userCache.getUser(userId) - await events.auth.logout(user.email) + let user: User | undefined + try { + user = await userCache.getUser(userId) + } catch { + user = undefined + } + await events.auth.logout(user?.email) await userCache.invalidateUser(userId) } diff --git a/packages/backend-core/src/events/publishers/auth.ts b/packages/backend-core/src/events/publishers/auth.ts index d63acbc469..e275d2dbb0 100644 --- a/packages/backend-core/src/events/publishers/auth.ts +++ b/packages/backend-core/src/events/publishers/auth.ts @@ -24,7 +24,7 @@ async function login(source: LoginSource, email: string) { await publishEvent(Event.AUTH_LOGIN, properties) } -async function logout(email: string) { +async function logout(email?: string) { const identity = await identification.getCurrentIdentity() const properties: LogoutEvent = { userId: identity.id, diff --git a/packages/types/src/sdk/events/auth.ts b/packages/types/src/sdk/events/auth.ts index fd97dd3b46..c7171d923d 100644 --- a/packages/types/src/sdk/events/auth.ts +++ b/packages/types/src/sdk/events/auth.ts @@ -15,7 +15,7 @@ export interface LoginEvent extends BaseEvent { export interface LogoutEvent extends BaseEvent { userId: string audited: { - email: string + email?: string } }