@@ -5,6 +5,8 @@ import { createGetAuth, getAuth } from './createGetAuth';
5
5
6
6
// { alg: 'HS256' }.{ sub: 'user-id' }.sig
7
7
const mockToken = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyLWlkIn0.0u5CllULtDVD9DUUmUMdJLbBCSNcnv4j3hCaPz4dNr8' ;
8
+ // { alg: 'HS256' }.{ sub: 'user-id-2' }.sig
9
+ const mockToken2 = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyLWlkLTIifQ.K-mhz0Ber1Hfh2xCwmvsLwhZO_IKLtKt78KTHsecEas' ;
8
10
9
11
describe ( 'createGetAuth(opts)' , ( ) => {
10
12
it ( 'returns a getAuth function' , ( ) => {
@@ -38,6 +40,20 @@ describe('getAuth(req)', () => {
38
40
expect ( getAuth ( req ) . userId ) . toEqual ( null ) ;
39
41
} ) ;
40
42
43
+ it ( 'prioritizes the token found in the auth header if a cookie token also exists' , ( ) => {
44
+ const req = new NextRequest ( 'https://www.clerk.com' , {
45
+ headers : new Headers ( {
46
+ [ constants . Headers . AuthStatus ] : AuthStatus . SignedIn ,
47
+ [ constants . Headers . AuthToken ] : mockToken ,
48
+ [ constants . Headers . AuthMessage ] : 'message' ,
49
+ [ constants . Headers . AuthReason ] : 'reason' ,
50
+ Cookie : `__session=${ mockToken2 } ;` ,
51
+ } ) ,
52
+ } ) ;
53
+
54
+ expect ( getAuth ( req ) . userId ) . toEqual ( 'user-id' ) ;
55
+ } ) ;
56
+
41
57
it ( 'throws if auth status is not found' , ( ) => {
42
58
const req = new NextRequest ( 'https://www.clerk.com' , {
43
59
headers : new Headers ( {
0 commit comments