Skip to content

Commit 79e9867

Browse files
committed
chore(nextjs): Improve createGetAuth test coverage
1 parent a1ae457 commit 79e9867

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/nextjs/src/server/createGetAuth.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { createGetAuth, getAuth } from './createGetAuth';
55

66
// { alg: 'HS256' }.{ sub: 'user-id' }.sig
77
const mockToken = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyLWlkIn0.0u5CllULtDVD9DUUmUMdJLbBCSNcnv4j3hCaPz4dNr8';
8+
// { alg: 'HS256' }.{ sub: 'user-id-2' }.sig
9+
const mockToken2 = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyLWlkLTIifQ.K-mhz0Ber1Hfh2xCwmvsLwhZO_IKLtKt78KTHsecEas';
810

911
describe('createGetAuth(opts)', () => {
1012
it('returns a getAuth function', () => {
@@ -38,6 +40,20 @@ describe('getAuth(req)', () => {
3840
expect(getAuth(req).userId).toEqual(null);
3941
});
4042

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+
4157
it('throws if auth status is not found', () => {
4258
const req = new NextRequest('https://www.clerk.com', {
4359
headers: new Headers({

0 commit comments

Comments
 (0)