@@ -21,15 +21,15 @@ function getStackServerSecret() {
2121}
2222
2323/**
24- * Returns the previous `STACK_SERVER_SECRET`
24+ * Returns the previous `STACK_SERVER_SECRET` during a rotation, or `null` if none is set.
2525 *
2626 * When set, keys derived from this secret are accepted for verification (JWTs and OIDC cookies)
2727 * but never used for signing new artifacts. Remove the env var once the grace window has
2828 * elapsed — see the self-host rotation runbook.
2929 */
30- export function getOldStackServerSecret ( ) : string {
31- const STACK_SERVER_SECRET_OLD = getEnvVariable ( " STACK_SERVER_SECRET_OLD" , "" ) ;
32- if ( ! STACK_SERVER_SECRET_OLD ) return "" ;
30+ export function getOldStackServerSecret ( ) : string | null {
31+ const STACK_SERVER_SECRET_OLD = process . env . STACK_SERVER_SECRET_OLD ;
32+ if ( ! STACK_SERVER_SECRET_OLD ) return null ;
3333 try {
3434 jose . base64url . decode ( STACK_SERVER_SECRET_OLD ) ;
3535 } catch ( e ) {
@@ -147,7 +147,7 @@ export async function getPrivateJwks(options: {
147147 const primarySecret = getStackServerSecret ( ) ;
148148 const oldSecret = getOldStackServerSecret ( ) ;
149149 const primaryPair = await derivePairForSecret ( primarySecret ) ;
150- const oldPair = oldSecret && oldSecret !== primarySecret ? await derivePairForSecret ( oldSecret ) : [ ] ;
150+ const oldPair = oldSecret !== null && oldSecret !== primarySecret ? await derivePairForSecret ( oldSecret ) : [ ] ;
151151
152152 // Signing uses index 0 (primary secret, legacy derivation). Verify accepts all entries.
153153 return [ ...primaryPair , ...oldPair ] ;
0 commit comments