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
17 changes: 17 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,23 @@ model Notification {
metadata Json?
}

/// Refresh tokens for secure session management
/// Opaque random byte strings (not JWTs) mapped to users
model RefreshToken {
id String @id @default(cuid())
token String @unique /// Opaque hashed token stored
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
expiresAt DateTime
createdAt DateTime @default(now())
replacedBy String? /// Points to the new token after rotation (for replay detection)
revokedAt DateTime?

@@index([userId])
@@index([token])
@@map("refresh_tokens")
}

model PrivacySettings {
id String @id @default(cuid())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Expand Down
16 changes: 13 additions & 3 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JwtStrategy } from './strategies/jwt.strategy';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { RoleGuard } from './guards/role.guard';
import { PrismaModule } from '../prisma/prisma.module';
import { RefreshTokenService } from './refresh-token.service';

@Module({
imports: [
Expand All @@ -19,14 +20,23 @@ import { PrismaModule } from '../prisma/prisma.module';
useFactory: async (configService: ConfigService) => ({
secret: configService.get<string>('JWT_SECRET') || 'your-secret-key',
signOptions: {
expiresIn: 900, // 15 minutes in seconds (default)
expiresIn: '15m', // 15 minutes — short-lived access token
},
}),
inject: [ConfigService],
}),
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy, JwtAuthGuard, RoleGuard],
exports: [AuthService, JwtStrategy, JwtAuthGuard, RoleGuard, PassportModule],
providers: [
AuthService,
JwtStrategy,
JwtAuthGuard,
RoleGuard,
RefreshTokenService,
],
exports: [
AuthService, JwtStrategy, JwtAuthGuard, RoleGuard,
PassportModule, RefreshTokenService,
],
})
export class AuthModule {}
Loading