forked from cardosofelipe/fast-next-template
Add async-safe polyfills, Jest custom config, and improved token validation
- Introduced Web Crypto API polyfills (`@peculiar/webcrypto`) for Node.js to enable SSR-safe cryptography utilities. - Added Jest setup file for global mocks (e.g., `localStorage`, `sessionStorage`, and `TextEncoder/Decoder`). - Enhanced token validation behavior in `storage` tests to reject incomplete tokens. - Replaced runtime configuration validation with clamping using `parseIntSafe` constraints for improved reliability. - Updated `package.json` and `package-lock.json` to include new dependencies (`@peculiar/webcrypto` and related libraries).
This commit is contained in:
@@ -130,6 +130,7 @@ export type AppConfig = typeof config;
|
||||
|
||||
/**
|
||||
* Validate critical configuration on module load
|
||||
* Note: Most auth config validation is handled by parseIntSafe min/max constraints
|
||||
*/
|
||||
function validateConfig(): void {
|
||||
const errors: string[] = [];
|
||||
@@ -143,14 +144,9 @@ function validateConfig(): void {
|
||||
errors.push('API timeout must be at least 1000ms');
|
||||
}
|
||||
|
||||
// Validate auth configuration
|
||||
if (config.auth.accessTokenExpiry <= 0) {
|
||||
errors.push('Access token expiry must be positive');
|
||||
}
|
||||
|
||||
if (config.auth.refreshTokenExpiry <= config.auth.accessTokenExpiry) {
|
||||
errors.push('Refresh token expiry must be greater than access token expiry');
|
||||
}
|
||||
// Auth configuration is validated by parseIntSafe constraints:
|
||||
// - accessTokenExpiry: min 60000ms (1 minute)
|
||||
// - refreshTokenExpiry: min 3600000ms (1 hour), which ensures it's always > access token
|
||||
|
||||
if (errors.length > 0) {
|
||||
console.error('Configuration validation failed:');
|
||||
|
||||
Reference in New Issue
Block a user