Skip to content

Commit 4d75ad8

Browse files
committed
Add changeset
1 parent a7343bb commit 4d75ad8

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

.changeset/flat-papers-begin.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@clerk/backend': minor
3+
'@clerk/express': minor
4+
---
5+
6+
Introduce `treatPendingAsSignedOut` option to `getAuth`
7+
8+
```ts
9+
// `pending` sessions will be treated as signed-out by default
10+
const { userId } = getAuth(req)
11+
```
12+
13+
```ts
14+
// Both `active` and `pending` sessions will be treated as authenticated when `treatPendingAsSignedOut` is false
15+
const { userId } = getAuth(req, { treatPendingAsSignedOut: false })
16+
```

packages/backend/src/tokens/authStatus.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function signedIn(
9999
afterSignInUrl: authenticateContext.afterSignInUrl || '',
100100
after#Url: authenticateContext.after#Url || '',
101101
isSignedIn: true,
102-
// @ts-expect-error Dynamically return `SignedOutAuthObject` based on options
102+
// @ts-expect-error The return type is intentionally overridden here to support consumer-facing logic that treats pending sessions as signed out. This override does not affect internal session management like handshake flows.
103103
toAuth: ({ treatPendingAsSignedOut = true } = {}) => {
104104
if (treatPendingAsSignedOut && authObject.sessionStatus === 'pending') {
105105
return signedOutAuthObject(undefined, authObject.sessionStatus);

packages/express/src/__tests__/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function mockRequest(): ExpressRequest {
2828

2929
export function mockRequestWithAuth(auth: Partial<AuthObject> = {}): ExpressRequestWithAuth {
3030
return {
31-
auth: {
31+
auth: () => ({
3232
sessionClaims: null,
3333
sessionId: null,
3434
actor: null,
@@ -41,7 +41,7 @@ export function mockRequestWithAuth(auth: Partial<AuthObject> = {}): ExpressRequ
4141
has: () => false,
4242
debug: () => ({}),
4343
...auth,
44-
},
44+
}),
4545
} as unknown as ExpressRequestWithAuth;
4646
}
4747

packages/express/src/getAuth.ts

-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ export const getAuth = (req: ExpressRequest, options?: GetAuthOptions): AuthObje
2020
throw new Error(middlewareRequired('getAuth'));
2121
}
2222

23-
// this has to receive an option
2423
return req.auth(options);
2524
};

0 commit comments

Comments
 (0)