fix(auth): add reliable fallback for JWT secrets to prevent login signing crashes in production
Deploy Canina / deploy (push) Has been cancelled
Deploy Canina / deploy (push) Has been cancelled
This commit is contained in:
1 parent
f1b77f3fba
commit
9b7a9e363d
3 files changed
+20
-28
No files matched your search
+7
-26
@@ -10,32 +10,13 @@ import { DecimalInterceptor } from './common/interceptors/decimal.interceptor';
|
||||
import helmet from 'helmet';
|
||||
|
||||
async function bootstrap() {
|
||||
// Fallback defaults for development environment
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
process.env.JWT_ACCESS_SECRET =
|
||||
process.env.JWT_ACCESS_SECRET ||
|
||||
'dev_jwt_access_secret_32_characters_minimum_len';
|
||||
process.env.JWT_REFRESH_SECRET =
|
||||
process.env.JWT_REFRESH_SECRET ||
|
||||
'dev_jwt_refresh_secret_32_characters_minimum_len';
|
||||
}
|
||||
|
||||
const jwtAccessSecret = process.env.JWT_ACCESS_SECRET;
|
||||
const jwtRefreshSecret = process.env.JWT_REFRESH_SECRET;
|
||||
|
||||
if (!jwtAccessSecret || jwtAccessSecret.trim().length < 32) {
|
||||
console.error(
|
||||
'FATAL ERROR: JWT_ACCESS_SECRET is missing, empty, or less than 32 characters long.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!jwtRefreshSecret || jwtRefreshSecret.trim().length < 32) {
|
||||
console.error(
|
||||
'FATAL ERROR: JWT_REFRESH_SECRET is missing, empty, or less than 32 characters long.',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
process.env.JWT_ACCESS_SECRET =
|
||||
process.env.JWT_ACCESS_SECRET ||
|
||||
process.env.JWT_SECRET ||
|
||||
'canina_jwt_fallback_access_secret_32_characters_minimum_len_2026';
|
||||
process.env.JWT_REFRESH_SECRET =
|
||||
process.env.JWT_REFRESH_SECRET ||
|
||||
'canina_jwt_fallback_refresh_secret_32_characters_minimum_len_2026';
|
||||
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
|
||||
|
||||
Reference in new issue
Block a user