File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,8 +11,13 @@ export const config = {
1111 secure : process . env . NODE_ENV === 'production' ,
1212} ;
1313
14- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
15- export const secretKey = createSecretKey ( process . env . JWT_SECRET ! , 'utf-8' ) ;
14+ function getSecretKey ( ) {
15+ const jwtSecret = process . env . JWT_SECRET ;
16+ if ( ! jwtSecret ) {
17+ throw new Error ( 'JWT_SECRET environment variable is required' ) ;
18+ }
19+ return createSecretKey ( jwtSecret , 'utf-8' ) ;
20+ }
1621
1722export interface SessionPayload {
1823 userId : string ;
@@ -25,7 +30,7 @@ export async function createSession(payload: SessionPayload) {
2530 . setIssuedAt ( )
2631 . setIssuer ( config . issuer )
2732 . setExpirationTime ( Math . floor ( Date . now ( ) / 1000 ) + config . expiration )
28- . sign ( secretKey ) ;
33+ . sign ( getSecretKey ( ) ) ;
2934
3035 const cookieStore = await cookies ( ) ;
3136 cookieStore . set ( config . cookieName , session , {
@@ -48,7 +53,7 @@ export async function verifySession(): Promise<SessionPayload | null> {
4853 }
4954
5055 try {
51- const { payload } = await jwtVerify ( session , secretKey , {
56+ const { payload } = await jwtVerify ( session , getSecretKey ( ) , {
5257 issuer : config . issuer ,
5358 } ) ;
5459
You can’t perform that action at this time.
0 commit comments