Skip to content
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

fix(nextjs): Drop user, session, organization from auth() #1947

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/thin-phones-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Drop `user`, `session`, and `organization` resources from the returned value of `auth()`.
9 changes: 7 additions & 2 deletions packages/nextjs/src/server/getAuth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Organization, Session, SignedInAuthObject, SignedOutAuthObject, User } from '@clerk/backend';
import type { AuthObject, Organization, Session, SignedInAuthObject, SignedOutAuthObject, User } from '@clerk/backend';
import {
AuthStatus,
constants,
Expand All @@ -18,6 +18,8 @@ import { getAuthKeyFromRequest, getCookie, getHeader, injectSSRStateIntoObject }

type GetAuthOpts = Partial<SecretKeyOrApiKey>;

type AuthObjectWithoutResources<T extends AuthObject> = Omit<T, 'user' | 'organization' | 'session'>;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we need to rethink how the backend types propagate, as I think we shouldn't resort to this low-level workarounds here. This PR is fine as we need a quick fix, but we should revisit in the future

export const createGetAuth = ({
debugLoggerName,
noAuthStatusMessage,
Expand All @@ -26,7 +28,10 @@ export const createGetAuth = ({
debugLoggerName: string;
}) =>
withLogger(debugLoggerName, logger => {
return (req: RequestLike, opts?: GetAuthOpts): SignedInAuthObject | SignedOutAuthObject => {
return (
req: RequestLike,
opts?: GetAuthOpts,
): AuthObjectWithoutResources<SignedInAuthObject | SignedOutAuthObject> => {
const debug = getHeader(req, constants.Headers.EnableDebug) === 'true';
if (debug) {
logger.enable();
Expand Down
Loading