Skip to content

chore(backend,nextjs): Refactor unauthenticated auth object fallback to respect intent #6112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add isAuthenticated property to auth object
  • Loading branch information
wobsoriano committed Jun 13, 2025
commit cdf5ec8c87af0fe3e6282c9a4ec91b42a9265d2c
4 changes: 2 additions & 2 deletions .changeset/open-swans-count.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
'@clerk/backend': patch
'@clerk/nextjs': patch
'@clerk/backend': minor
'@clerk/nextjs': minor
---

Respect `acceptsToken` when returning unauthenticated session or machine object.
8 changes: 8 additions & 0 deletions packages/backend/src/tokens/authObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type SignedInAuthObject = SharedSignedInAuthObjectProperties & {
* Used to help debug issues when using Clerk in development.
*/
debug: AuthObjectDebug;
isAuthenticated: true;
};

/**
Expand All @@ -78,6 +79,7 @@ export type SignedOutAuthObject = {
getToken: ServerGetToken;
has: CheckAuthorizationFromSessionClaims;
debug: AuthObjectDebug;
isAuthenticated: false;
};

/**
Expand Down Expand Up @@ -121,6 +123,7 @@ export type AuthenticatedMachineObject<T extends MachineTokenType = MachineToken
has: CheckAuthorizationFromSessionClaims;
debug: AuthObjectDebug;
tokenType: T;
isAuthenticated: true;
} & MachineObjectExtendedProperties<true>[T]
: never;

Expand All @@ -141,6 +144,7 @@ export type UnauthenticatedMachineObject<T extends MachineTokenType = MachineTok
has: CheckAuthorizationFromSessionClaims;
debug: AuthObjectDebug;
tokenType: T;
isAuthenticated: false;
} & MachineObjectExtendedProperties<false>[T]
: never;

Expand Down Expand Up @@ -201,6 +205,7 @@ export function signedInAuthObject(
plans: (sessionClaims.pla as string) || '',
}),
debug: createDebug({ ...authenticateContext, sessionToken }),
isAuthenticated: true,
};
}

Expand All @@ -226,6 +231,7 @@ export function signedOutAuthObject(
getToken: () => Promise.resolve(null),
has: () => false,
debug: createDebug(debugData),
isAuthenticated: false,
};
}

Expand All @@ -244,6 +250,7 @@ export function authenticatedMachineObject<T extends MachineTokenType>(
getToken: () => Promise.resolve(token),
has: () => false,
debug: createDebug(debugData),
isAuthenticated: true,
};

// Type assertions are safe here since we know the verification result type matches the tokenType.
Expand Down Expand Up @@ -303,6 +310,7 @@ export function unauthenticatedMachineObject<T extends MachineTokenType>(
has: () => false,
getToken: () => Promise.resolve(null),
debug: createDebug(debugData),
isAuthenticated: false,
};

switch (tokenType) {
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy