diff --git a/.changeset/three-rings-wash.md b/.changeset/three-rings-wash.md new file mode 100644 index 00000000000..59ce3fbdea6 --- /dev/null +++ b/.changeset/three-rings-wash.md @@ -0,0 +1,5 @@ +--- +'@clerk/nextjs': patch +--- + +Deprecate `user`, `session`, and `organization` resources from the returned value of `auth()`. diff --git a/packages/nextjs/src/server/getAuth.ts b/packages/nextjs/src/server/getAuth.ts index cf37b838973..de28db9d9a5 100644 --- a/packages/nextjs/src/server/getAuth.ts +++ b/packages/nextjs/src/server/getAuth.ts @@ -8,6 +8,7 @@ import { signedInAuthObject, signedOutAuthObject, } from '@clerk/backend'; +import { deprecatedObjectProperty } from '@clerk/shared/deprecated'; import type { SecretKeyOrApiKey } from '@clerk/types'; import { withLogger } from '../utils/debugLogger'; @@ -18,7 +19,20 @@ import { getAuthKeyFromRequest, getCookie, getHeader, injectSSRStateIntoObject } type GetAuthOpts = Partial; -type AuthObjectWithoutResources = Omit; +type AuthObjectWithDeprecatedResources = Omit & { + /** + * @deprecated This will be removed in the next major version + */ + user: T['user']; + /** + * @deprecated This will be removed in the next major version + */ + organization: T['organization']; + /** + * @deprecated This will be removed in the next major version + */ + session: T['session']; +}; export const createGetAuth = ({ debugLoggerName, @@ -31,7 +45,7 @@ export const createGetAuth = ({ return ( req: RequestLike, opts?: GetAuthOpts, - ): AuthObjectWithoutResources => { + ): AuthObjectWithDeprecatedResources => { const debug = getHeader(req, constants.Headers.EnableDebug) === 'true'; if (debug) { logger.enable(); @@ -66,7 +80,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; }; });