Skip to content

Commit 2a22aad

Browse files
authoredNov 17, 2023
chore(types): Drop deprecations (#2109)
* chore(types): Drop `orgs` claim * chore(gatsby-plugin-clerk,types): Replace `ServerSideAuth` with `AuthObject` `AuthObject` is a kind of superset of `ServerSideAuth`. The only difference is that instead of `auth.claims` in `AuthObject` you need to use `auth.sessionClaims` * chore(types,clerk-react,nextjs): Drop `frontendApi` and `apiKey` * fix(clerk-expo): Fix building types * chore(*): Drop export and replace IsomorphicClerkOptions with ClerkProviderOptionsWrapper * chore(repo): Add changeset
1 parent e400fa9 commit 2a22aad

File tree

19 files changed

+75
-112
lines changed

19 files changed

+75
-112
lines changed
 

‎.changeset/long-beds-mate.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'gatsby-plugin-clerk': major
3+
'@clerk/nextjs': major
4+
'@clerk/clerk-react': major
5+
'@clerk/remix': major
6+
'@clerk/types': major
7+
---
8+
9+
Drop deprecations. Migration steps:
10+
- drop `orgs` jwt claim from session token
11+
- change type of `auth` param of `withServerAuth()` callback to `AuthObject` from `ServerSideAuth` in `gatsby-clerk-plugin`
12+
- use `auth.sessionClaims` instead of `auth.claims`
13+
- use `AuthObject` properties from `auth`
14+
- use `publishableKey` instead of `frontendApi`
15+
- use `ClerkProviderOptionsWrapper` type instead of `IsomorphicClerkOptions`

‎packages/expo/src/ClerkProvider.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ export function ClerkProvider(props: ClerkProviderProps): JSX.Element {
2222
const key = publishableKey || process.env.CLERK_PUBLISHABLE_KEY || '';
2323

2424
return (
25-
//@ts-expect-error
2625
<ClerkReactProvider
27-
// Force reset the state when the provided key changes, this ensures that the provider does not retain stale state. See JS-598 for additional context.
26+
// Force reset the state when the provided key changes, this ensures that the provider does not retain stale state.
27+
// See JS-598 for additional context.
2828
key={key}
2929
{...rest}
30+
publishableKey={key}
3031
Clerk={buildClerk({ key, tokenCache })}
3132
standardBrowser={!isReactNative()}
3233
>

‎packages/gatsby-plugin-clerk/src/GatsbyClerkProvider.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
1+
import type { ClerkProviderProps } from '@clerk/clerk-react';
22
import {
33
__internal__setErrorThrowerOptions,
44
ClerkLoaded,
@@ -15,9 +15,8 @@ const SDK_METADATA = {
1515
__internal__setErrorThrowerOptions({ packageName: 'gatsby-plugin-clerk' });
1616

1717
export type GatsbyClerkProviderProps = {
18-
children: React.ReactNode;
1918
clerkState: any;
20-
} & IsomorphicClerkOptions;
19+
} & ClerkProviderProps;
2120

2221
export function ClerkProvider({ children, ...rest }: GatsbyClerkProviderProps) {
2322
const { clerkState, ...restProps } = rest;

‎packages/gatsby-plugin-clerk/src/ssr/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import type { AuthenticateRequestOptions, Organization, Session, User } from '@clerk/backend';
2-
import type { ServerSideAuth } from '@clerk/types';
1+
import type { AuthenticateRequestOptions, AuthObject, Organization, Session, User } from '@clerk/backend';
32
import type { GetServerDataProps } from 'gatsby';
43

54
export type WithServerAuthResult<CallbackReturn> = (props: GetServerDataProps) => Promise<Awaited<CallbackReturn>>;
65

76
export type GetServerDataPropsWithAuth<Options extends WithServerAuthOptions = any> = GetServerDataProps & {
8-
auth: ServerSideAuth;
7+
auth: AuthObject;
98
} & (Options extends { loadSession: true } ? { session: Session | null } : object) &
109
(Options extends { loadUser: true } ? { user: User | null } : object) &
1110
(Options extends { loadOrg: true } ? { organization: Organization | null } : object);

‎packages/gatsby-plugin-clerk/src/ssr/withServerAuth.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export const withServerAuth: WithServerAuth = (cbOrOptions: any, options?: any):
3030
});
3131
return injectSSRStateIntoProps({ headers }, { __clerk_ssr_interstitial_html: interstitialHtml });
3232
}
33-
const legacyAuthData = { ...requestState.toAuth(), claims: requestState?.toAuth()?.sessionClaims };
34-
const contextWithAuth = injectAuthIntoContext(props, legacyAuthData);
33+
34+
const contextWithAuth = injectAuthIntoContext(props, requestState.toAuth());
3535
const callbackResult = (await callback?.(contextWithAuth)) || {};
36-
return injectSSRStateIntoProps(callbackResult, { __clerk_ssr_state: sanitizeAuthObject(legacyAuthData) });
36+
return injectSSRStateIntoProps(callbackResult, { __clerk_ssr_state: sanitizeAuthObject(contextWithAuth.auth) });
3737
};
3838
};

‎packages/nextjs/src/app-router/server/ClerkProvider.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
2-
import type { InitialState, PublishableKeyOrFrontendApi } from '@clerk/types';
1+
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
2+
import type { InitialState } from '@clerk/types';
33
import React from 'react';
44

55
import { mergeNextClerkPropsWithEnv } from '../../utils/mergeNextClerkPropsWithEnv';
66
import { ClientClerkProvider } from '../client/ClerkProvider';
77
import { initialState } from './auth';
88

9-
type NextAppClerkProviderProps = React.PropsWithChildren<
10-
Omit<IsomorphicClerkOptions, keyof PublishableKeyOrFrontendApi> & Partial<PublishableKeyOrFrontendApi>
11-
>;
9+
type NextAppClerkProviderProps = ClerkProviderOptionsWrapper;
1210

1311
export function ClerkProvider(props: NextAppClerkProviderProps) {
1412
const { children, ...rest } = props;

‎packages/nextjs/src/server/getAuth.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import {
88
signedInAuthObject,
99
signedOutAuthObject,
1010
} from '@clerk/backend';
11-
import type { SecretKeyOrApiKey } from '@clerk/types';
1211

1312
import { withLogger } from '../utils/debugLogger';
1413
import { API_URL, API_VERSION, SECRET_KEY } from './constants';
1514
import { getAuthAuthHeaderMissing } from './errors';
1615
import type { RequestLike } from './types';
1716
import { getAuthKeyFromRequest, getCookie, getHeader, injectSSRStateIntoObject } from './utils';
1817

19-
type GetAuthOpts = Partial<SecretKeyOrApiKey>;
20-
2118
type AuthObjectWithoutResources<T extends AuthObject> = Omit<T, 'user' | 'organization' | 'session'>;
2219

2320
export const createGetAuth = ({
@@ -30,7 +27,7 @@ export const createGetAuth = ({
3027
withLogger(debugLoggerName, logger => {
3128
return (
3229
req: RequestLike,
33-
opts?: GetAuthOpts,
30+
opts?: { secretKey?: string },
3431
): AuthObjectWithoutResources<SignedInAuthObject> | AuthObjectWithoutResources<SignedOutAuthObject> => {
3532
const debug = getHeader(req, constants.Headers.EnableDebug) === 'true';
3633
if (debug) {

‎packages/nextjs/src/server/types.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OptionalVerifyTokenOptions } from '@clerk/backend';
2-
import type { MultiDomainAndOrProxy, PublishableKeyOrFrontendApi, SecretKeyOrApiKey } from '@clerk/types';
2+
import type { MultiDomainAndOrProxy } from '@clerk/types';
33
import type { IncomingMessage } from 'http';
44
import type { NextApiRequest } from 'next';
55
import type { NextApiRequestCookies } from 'next/dist/server/api-utils';
@@ -12,10 +12,10 @@ type GsspRequest = IncomingMessage & {
1212

1313
export type RequestLike = NextRequest | NextApiRequest | GsspRequest;
1414

15-
export type WithAuthOptions = Partial<PublishableKeyOrFrontendApi> &
16-
Partial<SecretKeyOrApiKey> &
17-
OptionalVerifyTokenOptions &
15+
export type WithAuthOptions = OptionalVerifyTokenOptions &
1816
MultiDomainAndOrProxy & {
17+
publishableKey?: string;
18+
secretKey?: string;
1919
signInUrl?: string;
2020
};
2121

‎packages/nextjs/src/types.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
2-
import type { MultiDomainAndOrProxy, PublishableKeyOrFrontendApi } from '@clerk/types';
3-
import type React from 'react';
1+
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
42

53
export type NextClerkProviderProps = {
6-
children: React.ReactNode;
74
/**
85
* If set to true, the NextJS middleware will be invoked
96
* every time the client-side auth state changes (sign-out, sign-in, organization switch etc.).
@@ -13,7 +10,4 @@ export type NextClerkProviderProps = {
1310
* @default true
1411
*/
1512
__unstable_invokeMiddlewareOnAuthStateChange?: boolean;
16-
} & Omit<IsomorphicClerkOptions, keyof PublishableKeyOrFrontendApi> &
17-
Partial<PublishableKeyOrFrontendApi> &
18-
Omit<IsomorphicClerkOptions, keyof MultiDomainAndOrProxy> &
19-
MultiDomainAndOrProxy;
13+
} & ClerkProviderOptionsWrapper;

‎packages/react/src/contexts/ClerkProvider.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { isPublishableKey } from '@clerk/shared/keys';
2-
import type { InitialState } from '@clerk/types';
32
import React from 'react';
43

54
import { multipleClerkProvidersError } from '../errors';
6-
import type { IsomorphicClerkOptions } from '../types';
5+
import type { ClerkProviderProps } from '../types';
76
import { __internal__setErrorThrowerOptions, errorThrower, withMaxAllowedInstancesGuard } from '../utils';
87
import { ClerkContextProvider } from './ClerkContextProvider';
98
import { StructureContext, StructureContextStates } from './StructureContext';
@@ -12,11 +11,6 @@ __internal__setErrorThrowerOptions({
1211
packageName: '@clerk/clerk-react',
1312
});
1413

15-
export type ClerkProviderProps = IsomorphicClerkOptions & {
16-
children: React.ReactNode;
17-
initialState?: InitialState;
18-
};
19-
2014
function ClerkProviderBase(props: ClerkProviderProps): JSX.Element {
2115
const { initialState, children, ...restIsomorphicClerkOptions } = props;
2216
const { publishableKey = '', Clerk: userInitialisedClerk } = restIsomorphicClerkOptions;

‎packages/react/src/contexts/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export { ClerkProvider, __internal__setErrorThrowerOptions } from './ClerkProvider';
2-
export type { ClerkProviderProps } from './ClerkProvider';

‎packages/react/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export type {
99
BrowserClerk,
1010
ClerkProp,
1111
HeadlessBrowserClerk,
12-
IsomorphicClerkOptions,
12+
ClerkProviderOptionsWrapper,
13+
ClerkProviderProps,
1314
WithClerkProp,
1415
WithSessionProp,
1516
WithUserProp,

‎packages/react/src/isomorphicClerk.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type MethodCallback = () => Promise<unknown> | unknown;
5757

5858
export class IsomorphicClerk {
5959
private readonly mode: 'browser' | 'server';
60-
private readonly publishableKey?: string;
6160
private readonly options: IsomorphicClerkOptions;
6261
private readonly Clerk: ClerkProp;
6362
private clerkjs: BrowserClerk | HeadlessBrowserClerk | null = null;
@@ -80,6 +79,11 @@ export class IsomorphicClerk {
8079
#loaded = false;
8180
#domain: DomainOrProxyUrl['domain'];
8281
#proxyUrl: DomainOrProxyUrl['proxyUrl'];
82+
#publishableKey: string;
83+
84+
get publishableKey(): string {
85+
return this.#publishableKey;
86+
}
8387

8488
get loaded(): boolean {
8589
return this.#loaded;
@@ -124,7 +128,7 @@ export class IsomorphicClerk {
124128

125129
constructor(options: IsomorphicClerkOptions) {
126130
const { Clerk = null, publishableKey } = options || {};
127-
this.publishableKey = publishableKey;
131+
this.#publishableKey = publishableKey;
128132
this.#proxyUrl = options?.proxyUrl;
129133
this.#domain = options?.domain;
130134
this.options = options;
@@ -149,7 +153,7 @@ export class IsomorphicClerk {
149153
// - https://github.com/remix-run/remix/issues/2947
150154
// - https://github.com/facebook/react/issues/24430
151155
if (typeof window !== 'undefined') {
152-
window.__clerk_publishable_key = this.publishableKey;
156+
window.__clerk_publishable_key = this.#publishableKey;
153157
window.__clerk_proxy_url = this.proxyUrl;
154158
window.__clerk_domain = this.domain;
155159
}
@@ -161,7 +165,7 @@ export class IsomorphicClerk {
161165

162166
if (isConstructor<BrowserClerkConstructor | HeadlessBrowserClerkConstrutor>(this.Clerk)) {
163167
// Construct a new Clerk object if a constructor is passed
164-
c = new this.Clerk(this.publishableKey || '', {
168+
c = new this.Clerk(this.#publishableKey, {
165169
proxyUrl: this.proxyUrl,
166170
domain: this.domain,
167171
} as any);
@@ -181,7 +185,7 @@ export class IsomorphicClerk {
181185
if (!global.Clerk) {
182186
await loadClerkJsScript({
183187
...this.options,
184-
publishableKey: this.publishableKey,
188+
publishableKey: this.#publishableKey,
185189
proxyUrl: this.proxyUrl,
186190
domain: this.domain,
187191
});

‎packages/react/src/types.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type {
33
ClerkOptions,
44
ClientResource,
55
DomainOrProxyUrl,
6+
InitialState,
67
LoadedClerk,
78
MultiDomainAndOrProxy,
8-
PublishableKeyOrFrontendApi,
99
SDKMetadata,
1010
SessionResource,
1111
SignInRedirectOptions,
@@ -23,15 +23,33 @@ declare global {
2323
}
2424
}
2525

26-
// TODO(@dimkl): Remove frontendApi when it's removed from ClerkOptions in @clerk/types
27-
export type IsomorphicClerkOptions = Omit<ClerkOptions, 'isSatellite' | 'frontendApi'> & {
26+
export type IsomorphicClerkOptions = Omit<ClerkOptions, 'isSatellite'> & {
2827
Clerk?: ClerkProp;
2928
clerkJSUrl?: string;
3029
clerkJSVariant?: 'headless' | '';
3130
clerkJSVersion?: string;
3231
sdkMetadata?: SDKMetadata;
33-
} & PublishableKeyOrFrontendApi &
34-
MultiDomainAndOrProxy;
32+
publishableKey: string;
33+
} & MultiDomainAndOrProxy;
34+
35+
export type ClerkProviderProps = IsomorphicClerkOptions & {
36+
children: React.ReactNode;
37+
initialState?: InitialState;
38+
};
39+
40+
// TODO(@dimkl): replacing it with the following make nextjs type tests fail
41+
// `Exclude<IsomorphicClerkOptions, 'publishableKey'> & { publishableKey?: string }`
42+
// find another way to reduce the duplication.
43+
export type ClerkProviderOptionsWrapper = Omit<ClerkOptions, 'isSatellite'> & {
44+
Clerk?: ClerkProp;
45+
clerkJSUrl?: string;
46+
clerkJSVariant?: 'headless' | '';
47+
clerkJSVersion?: string;
48+
sdkMetadata?: SDKMetadata;
49+
publishableKey?: string;
50+
} & MultiDomainAndOrProxy & {
51+
children: React.ReactNode;
52+
};
3553

3654
export interface BrowserClerkConstructor {
3755
new (publishableKey: string, options?: DomainOrProxyUrl): BrowserClerk;

‎packages/remix/src/client/RemixClerkProvider.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
1+
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
22
import { ClerkProvider as ReactClerkProvider } from '@clerk/clerk-react';
33
import React from 'react';
44

@@ -15,9 +15,8 @@ const SDK_METADATA = {
1515
};
1616

1717
export type RemixClerkProviderProps = {
18-
children: React.ReactNode;
1918
clerkState: ClerkState;
20-
} & IsomorphicClerkOptions;
19+
} & ClerkProviderOptionsWrapper;
2120

2221
/**
2322
* Remix hydration errors should not stop Clerk navigation from working, as the components mount only after

‎packages/remix/src/client/types.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
2-
import type { InitialState, MultiDomainAndOrProxy, PublishableKeyOrFrontendApi } from '@clerk/types';
3-
import type { PropsWithChildren } from 'react';
1+
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
2+
import type { InitialState } from '@clerk/types';
43

54
export type ClerkState = {
65
__type: 'clerkState';
@@ -26,9 +25,4 @@ export type WithClerkState<U = any> = {
2625
clerkState: { __type: 'clerkState' };
2726
};
2827

29-
export type RemixClerkProviderProps = PropsWithChildren<
30-
Omit<IsomorphicClerkOptions, keyof PublishableKeyOrFrontendApi> &
31-
Partial<PublishableKeyOrFrontendApi> &
32-
Omit<IsomorphicClerkOptions, keyof MultiDomainAndOrProxy> &
33-
MultiDomainAndOrProxy
34-
>;
28+
export type RemixClerkProviderProps = ClerkProviderOptionsWrapper;

‎packages/types/src/jwtv2.ts

-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ export interface JwtPayload extends CustomJwtSessionClaims {
8181
*/
8282
act?: ActClaim;
8383

84-
/**
85-
* @deprecated - Add orgs to your session token using the "user.organizations" shortcode in JWT Templates instead
86-
*/
87-
orgs?: Record<string, MembershipRole>;
88-
8984
/**
9085
* Active organization id.
9186
*/

‎packages/types/src/key.ts

-32
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,3 @@ export type PublishableKey = {
44
frontendApi: string;
55
instanceType: InstanceType;
66
};
7-
8-
export type PublishableKeyOrFrontendApi =
9-
| {
10-
/**
11-
* @deprecated Use `publishableKey` instead.
12-
*/
13-
frontendApi?: never;
14-
publishableKey: string;
15-
}
16-
| {
17-
/**
18-
* @deprecated Use `publishableKey` instead.
19-
*/
20-
frontendApi: string;
21-
publishableKey?: never;
22-
};
23-
24-
export type SecretKeyOrApiKey =
25-
| {
26-
secretKey?: never;
27-
/**
28-
* @deprecated Use `secretKey` instead.
29-
*/
30-
apiKey: string;
31-
}
32-
| {
33-
secretKey: string;
34-
/**
35-
* @deprecated Use `secretKey` instead.
36-
*/
37-
apiKey?: never;
38-
};

‎packages/types/src/ssr.ts

-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ActJWTClaim, ClerkJWTClaims } from './jwt';
21
import type { ActClaim, JwtPayload } from './jwtv2';
32
import type { OrganizationResource } from './organization';
43
import type { MembershipRole } from './organizationMembership';
@@ -9,17 +8,6 @@ import type { Serializable } from './utils';
98
export type ServerGetTokenOptions = { template?: string };
109
export type ServerGetToken = (options?: ServerGetTokenOptions) => Promise<string | null>;
1110

12-
/**
13-
* @deprecated
14-
*/
15-
export type ServerSideAuth = {
16-
sessionId: string | null;
17-
userId: string | null;
18-
actor: ActJWTClaim | null;
19-
getToken: ServerGetToken;
20-
claims: ClerkJWTClaims | null;
21-
};
22-
2311
export type InitialState = Serializable<{
2412
sessionClaims: JwtPayload;
2513
sessionId: string | undefined;

0 commit comments

Comments
 (0)
Please sign in to comment.