Skip to content

Commit

Permalink
fix(nextjs): Deprecate user, session, organization from auth() (#1960)
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef authored and octoper committed Oct 31, 2023
1 parent aff394e commit 146831a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/three-rings-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/nextjs': patch
---

Deprecate `user`, `session`, and `organization` resources from the returned value of `auth()`.
18 changes: 17 additions & 1 deletion packages/nextjs/src/server/getAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
signedInAuthObject,
signedOutAuthObject,
} from '@clerk/backend';
import { deprecatedObjectProperty } from '@clerk/shared';
import type { SecretKeyOrApiKey } from '@clerk/types';

import { withLogger } from '../utils/debugLogger';
Expand Down Expand Up @@ -66,7 +67,22 @@ export const createGetAuth = ({

const jwt = parseJwt(req);
logger.debug('JWT debug', jwt.raw.text);
return signedInAuthObject(jwt.payload, { ...options, token: jwt.raw.text });

const signedIn = signedInAuthObject(jwt.payload, { ...options, token: jwt.raw.text });

if (signedIn.user) {
deprecatedObjectProperty(signedIn, 'user', 'Use `clerkClient.users.getUser` instead.');
}

if (signedIn.organization) {
deprecatedObjectProperty(signedIn, 'organization', 'Use `clerkClient.organizations.getOrganization` instead.');
}

if (signedIn.session) {
deprecatedObjectProperty(signedIn, 'session', 'Use `clerkClient.sessions.getSession` instead.');
}

return signedIn;
};
});

Expand Down

0 comments on commit 146831a

Please sign in to comment.