Skip to content
Merged
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
12 changes: 7 additions & 5 deletions src/auth/auth-session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class AuthSessionService {
try {
payload = await this.jwtService.verifyAsync<RefreshTokenPayload>(
rawRefreshToken,
{ secret: this.refreshSecret },
{ secret: this.refreshSecret, algorithms: ["HS256"] },
);
} catch {
throw new UnauthorizedException({
Expand Down Expand Up @@ -305,10 +305,11 @@ export class AuthSessionService {
}

private get refreshSecret(): string {
return this.configService.get<string>(
"JWT_REFRESH_SECRET",
"refresh_secret",
);
const secret = this.configService.get<string>("JWT_REFRESH_SECRET");
if (!secret) {
throw new Error("JWT_REFRESH_SECRET is not configured");
}
return secret;
}

/**
Expand Down Expand Up @@ -376,6 +377,7 @@ export class AuthSessionService {
this.jwtService.signAsync(refreshPayload, {
secret: this.refreshSecret,
expiresIn: this.sessionPolicy.refreshTokenTtl,
algorithm: "HS256",
}),
]);

Expand Down
25 changes: 13 additions & 12 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtLearnerGuard } from './guards/jwt-learner.guard';
import { JwtTutorGuard } from './guards/jwt-tutor.guard';
import { JwtAdminGuard } from './guards/jwt-admin.guard';
import { RolesGuard } from './guards/roles.guard';
import { AuthSessionService } from './auth-session.service';
import { AuthSessionController } from './auth-session.controller';
import { Module } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { JwtLearnerGuard } from "./guards/jwt-learner.guard";
import { JwtTutorGuard } from "./guards/jwt-tutor.guard";
import { JwtAdminGuard } from "./guards/jwt-admin.guard";
import { RolesGuard } from "./guards/roles.guard";
import { AuthSessionService } from "./auth-session.service";
import { AuthSessionController } from "./auth-session.controller";

@Module({
imports: [
ConfigModule,
JwtModule.registerAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => {
const secret = config.get<string>('JWT_SECRET');
const secret = config.get<string>("JWT_SECRET");
if (!secret) {
throw new Error('JWT_SECRET is not configured');
throw new Error("JWT_SECRET is not configured");
}
return {
secret,
signOptions: { expiresIn: '15m' },
signOptions: { expiresIn: "15m", algorithm: "HS256" },
verifyOptions: { algorithms: ["HS256"] },
};
},
inject: [ConfigService],
Expand Down
Loading