This commit is contained in:
Philipinho
2026-03-26 17:29:25 +00:00
parent c6d2f0c6cc
commit 2648d7bea3
8 changed files with 26 additions and 13 deletions
@@ -716,5 +716,12 @@
"Unknown device": "Unknown device", "Unknown device": "Unknown device",
"No active sessions": "No active sessions", "No active sessions": "No active sessions",
"Session revoked": "Session revoked", "Session revoked": "Session revoked",
"All other sessions revoked": "All other sessions revoked" "All other sessions revoked": "All other sessions revoked",
"Last used": "Last used",
"Created": "Created",
"Rename": "Rename",
"Publish": "Publish",
"Security": "Security",
"Enforce SSO": "Enforce SSO",
"Once enforced, members will not be able to login with email and password.": "Once enforced, members will not be able to login with email and password."
} }
@@ -212,6 +212,7 @@ export class AuthController {
setAuthCookie(res: FastifyReply, token: string) { setAuthCookie(res: FastifyReply, token: string) {
res.setCookie('authToken', token, { res.setCookie('authToken', token, {
httpOnly: true, httpOnly: true,
sameSite: 'lax',
path: '/', path: '/',
expires: this.environmentService.getCookieExpiresIn(), expires: this.environmentService.getCookieExpiresIn(),
secure: this.environmentService.isHttps(), secure: this.environmentService.isHttps(),
@@ -51,7 +51,6 @@ export class SessionService {
const mapped = sessions.map((s) => ({ const mapped = sessions.map((s) => ({
id: s.id, id: s.id,
deviceName: s.deviceName, deviceName: s.deviceName,
ipAddress: s.ipAddress,
geoLocation: s.geoLocation, geoLocation: s.geoLocation,
lastActiveAt: s.lastActiveAt, lastActiveAt: s.lastActiveAt,
createdAt: s.createdAt, createdAt: s.createdAt,
@@ -669,13 +669,15 @@ export class WorkspaceService {
} }
} }
await this.userRepo.updateUser( await executeTx(this.db, async (trx) => {
{ deactivatedAt: new Date() }, await this.userRepo.updateUser(
userId, { deactivatedAt: new Date() },
workspaceId, userId,
); workspaceId,
trx,
await this.userSessionRepo.revokeByUserId(userId, workspaceId); );
await this.userSessionRepo.revokeByUserId(userId, workspaceId, trx);
});
this.auditService.log({ this.auditService.log({
event: AuditEvent.USER_DEACTIVATED, event: AuditEvent.USER_DEACTIVATED,
@@ -789,9 +791,9 @@ export class WorkspaceService {
await this.watcherRepo.deleteByUserAndWorkspace(userId, workspaceId, { await this.watcherRepo.deleteByUserAndWorkspace(userId, workspaceId, {
trx, trx,
}); });
});
await this.userSessionRepo.revokeByUserId(userId, workspaceId); await this.userSessionRepo.revokeByUserId(userId, workspaceId, trx);
});
this.auditService.log({ this.auditService.log({
event: AuditEvent.USER_DELETED, event: AuditEvent.USER_DELETED,
@@ -20,6 +20,7 @@ export async function up(db: Kysely<any>): Promise<void> {
col.notNull().defaultTo(sql`now()`), col.notNull().defaultTo(sql`now()`),
) )
.addColumn('expires_at', 'timestamptz', (col) => col.notNull()) .addColumn('expires_at', 'timestamptz', (col) => col.notNull())
.addColumn('metadata', 'jsonb')
.addColumn('revoked_at', 'timestamptz') .addColumn('revoked_at', 'timestamptz')
.addColumn('created_at', 'timestamptz', (col) => .addColumn('created_at', 'timestamptz', (col) =>
col.notNull().defaultTo(sql`now()`), col.notNull().defaultTo(sql`now()`),
@@ -89,8 +89,10 @@ export class UserSessionRepo {
async revokeByUserId( async revokeByUserId(
userId: string, userId: string,
workspaceId: string, workspaceId: string,
trx?: KyselyTransaction,
): Promise<void> { ): Promise<void> {
await this.db const db = dbOrTx(this.db, trx);
await db
.updateTable('userSessions') .updateTable('userSessions')
.set({ revokedAt: new Date() }) .set({ revokedAt: new Date() })
.where('userId', '=', userId) .where('userId', '=', userId)
+1
View File
@@ -437,6 +437,7 @@ export interface UserSessions {
userAgent: string | null; userAgent: string | null;
ipAddress: string | null; ipAddress: string | null;
geoLocation: string | null; geoLocation: string | null;
metadata: Json | null;
lastActiveAt: Generated<Timestamp>; lastActiveAt: Generated<Timestamp>;
expiresAt: Timestamp; expiresAt: Timestamp;
revokedAt: Timestamp | null; revokedAt: Timestamp | null;