PhiloMind / src /auth /auth.module.ts
github-actions[bot]
Deploy Backend from GitHub Actions Commit: ca37b2a1c9dd5c702619ea7ae7b3260d2fb5663d
b185a6d
Raw
History Blame Contribute Delete
972 Bytes
import { Module, forwardRef } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";
import { UsersModule } from "../users/users.module";
import { JwtStrategy } from "./jwt.strategy";
import { JwtAuthGuard } from "./jwt-auth.guard";
import { RolesGuard } from "./roles.guard";
const getJwtSecret = () => {
if (process.env.JWT_SECRET) return process.env.JWT_SECRET;
if (process.env.NODE_ENV === "production") {
throw new Error("JWT_SECRET must be configured in production");
}
return "philomind-dev-only-secret-change-me";
};
@Module({
imports: [
PassportModule.register({ defaultStrategy: "jwt" }),
JwtModule.register({
secret: getJwtSecret(),
signOptions: { expiresIn: "7d" },
}),
forwardRef(() => UsersModule),
],
providers: [JwtStrategy, JwtAuthGuard, RolesGuard],
exports: [PassportModule, JwtModule, JwtAuthGuard, RolesGuard],
})
export class AuthModule {}