@@ -3,13 +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 { getCookieSuffix , isDevelopmentFromSecretKey } from '../util/shared' ;
6
+ import { 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
+ import { getCookieName , getCookieValue } from './cookie' ;
13
13
import { verifyHandshakeToken } from './handshake' ;
14
14
import type { AuthenticateRequestOptions } from './types' ;
15
15
import { verifyToken } from './verify' ;
@@ -89,7 +89,7 @@ export async function authenticateRequest(
89
89
90
90
const url = new URL ( `https://${ frontendApiNoProtocol } /v1/client/handshake` ) ;
91
91
url . searchParams . append ( 'redirect_url' , redirectUrl ?. href || '' ) ;
92
- url . searchParams . append ( 'suffixed_cookies' , 'true' ) ;
92
+ url . searchParams . append ( 'suffixed_cookies' , authenticateContext . suffixedCookies . toString ( ) ) ;
93
93
94
94
if ( authenticateContext . instanceType === 'development' && authenticateContext . devBrowserToken ) {
95
95
url . searchParams . append ( constants . QueryParameters . DevBrowser , authenticateContext . devBrowserToken ) ;
@@ -106,16 +106,12 @@ export async function authenticateRequest(
106
106
107
107
const handshakePayload = await verifyHandshakeToken ( authenticateContext . handshakeToken ! , authenticateContext ) ;
108
108
const cookiesToSet = handshakePayload . handshake ;
109
- const cookieSuffix = getCookieSuffix ( authenticateContext . publishableKey ) ;
110
109
111
110
let sessionToken = '' ;
112
111
cookiesToSet . forEach ( ( x : string ) => {
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 ) ;
112
+ headers . append ( 'Set-Cookie' , x ) ;
113
+ if ( getCookieName ( x ) . startsWith ( constants . Cookies . Session ) ) {
114
+ sessionToken = getCookieValue ( x ) ;
119
115
}
120
116
} ) ;
121
117
0 commit comments