@@ -3,12 +3,13 @@ import type { TokenCarrier } from '../errors';
3
3
import { TokenVerificationError , TokenVerificationErrorReason } from '../errors' ;
4
4
import { decodeJwt } from '../jwt/verifyJwt' ;
5
5
import { assertValidSecretKey } from '../util/optionsAssertions' ;
6
- import { isDevelopmentFromSecretKey } from '../util/shared' ;
6
+ import { getCookieSuffix , isDevelopmentFromSecretKey } from '../util/shared' ;
7
7
import type { AuthenticateContext } from './authenticateContext' ;
8
8
import { createAuthenticateContext } from './authenticateContext' ;
9
9
import type { RequestState } from './authStatus' ;
10
10
import { AuthErrorReason , handshake , signedIn , signedOut } from './authStatus' ;
11
11
import { createClerkRequest } from './clerkRequest' ;
12
+ import { suffixCookie , unSuffixCookie } from './cookie' ;
12
13
import { verifyHandshakeToken } from './handshake' ;
13
14
import type { AuthenticateRequestOptions } from './types' ;
14
15
import { verifyToken } from './verify' ;
@@ -105,12 +106,16 @@ export async function authenticateRequest(
105
106
106
107
const handshakePayload = await verifyHandshakeToken ( authenticateContext . handshakeToken ! , authenticateContext ) ;
107
108
const cookiesToSet = handshakePayload . handshake ;
109
+ const cookieSuffix = getCookieSuffix ( authenticateContext . publishableKey ) ;
108
110
109
111
let sessionToken = '' ;
110
112
cookiesToSet . forEach ( ( x : string ) => {
111
- headers . append ( 'Set-Cookie' , x ) ;
112
- if ( x . startsWith ( `${ constants . Cookies . Session } =` ) ) {
113
- sessionToken = x . split ( ';' ) [ 0 ] . substring ( 10 ) ;
113
+ const suffixedCookie = suffixCookie ( cookieSuffix , x ) ;
114
+ headers . append ( 'Set-Cookie' , suffixedCookie ) ;
115
+ const unSuffixedCookie = unSuffixCookie ( cookieSuffix , x ) ;
116
+ headers . append ( 'Set-Cookie' , unSuffixedCookie ) ;
117
+ if ( unSuffixedCookie . startsWith ( `${ constants . Cookies . Session } =` ) ) {
118
+ sessionToken = unSuffixedCookie . split ( ';' ) [ 0 ] . substring ( 10 ) ;
114
119
}
115
120
} ) ;
116
121
0 commit comments