Skip to content

Commit d9b3215

Browse files
wobsorianochriscanincoderabbitai[bot]
authored
chore(expo): Remove Clerk instance export (#7519)
Co-authored-by: Christopher Canin <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent af85739 commit d9b3215

File tree

6 files changed

+64
-20
lines changed

6 files changed

+64
-20
lines changed

.changeset/tame-carpets-sink.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@clerk/expo': major
3+
---
4+
5+
Remove deprecated `Clerk` export in favor of `getClerkInstance()`.
6+
7+
```diff
8+
- import { Clerk } from '@clerk/clerk-expo';
9+
+ import { getClerkInstance } from '@clerk/expo';
10+
11+
- const token = await Clerk.session?.getToken();
12+
+ const token = await getClerkInstance().session?.getToken();
13+
```
14+
15+
If you need to create the instance before `ClerkProvider` renders, pass the `publishableKey`:
16+
17+
```tsx
18+
import { ClerkProvider, getClerkInstance } from '@clerk/expo';
19+
20+
const clerkInstance = getClerkInstance({ publishableKey: 'pk_xxx' });
21+
22+
// Use the instance outside of React
23+
const token = await clerkInstance?.session?.getToken();
24+
fetch('https://example.com/api', { headers: { Authorization: `Bearer ${token}` } });
25+
```
26+
27+
> [!NOTE]
28+
> - Calling `getClerkInstance()` with different publishable keys will create a new Clerk instance.
29+
> - If `getClerkInstance` is called without a publishable key, and `ClerkProvider` has not rendered yet, an error will be thrown.

packages/expo/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ export {
88
isClerkRuntimeError,
99
} from '@clerk/react/errors';
1010

11-
/**
12-
* @deprecated Use `getClerkInstance()` instead.
13-
*/
14-
export { clerk as Clerk } from './provider/singleton';
1511
export { getClerkInstance } from './provider/singleton';
1612

1713
export * from './provider/ClerkProvider';

packages/expo/src/provider/singleton/createClerkInstance.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import type { BuildClerkOptions } from './types';
2525

2626
const KEY = '__clerk_client_jwt';
2727

28-
/**
29-
* @deprecated Use `getClerkInstance()` instead. `Clerk` will be removed in the next major version.
30-
*/
31-
export let clerk: HeadlessBrowserClerk | BrowserClerk;
3228
let __internal_clerk: HeadlessBrowserClerk | BrowserClerk | undefined;
3329

3430
export function createClerkInstance(ClerkClass: typeof Clerk) {
@@ -53,7 +49,7 @@ export function createClerkInstance(ClerkClass: typeof Clerk) {
5349

5450
const getToken = tokenCache.getToken;
5551
const saveToken = tokenCache.saveToken;
56-
__internal_clerk = clerk = new ClerkClass(publishableKey);
52+
__internal_clerk = new ClerkClass(publishableKey);
5753

5854
if (Platform.OS === 'ios' || Platform.OS === 'android') {
5955
// @ts-expect-error - This is an internal API

packages/expo/src/provider/singleton/singleton.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { Clerk } from '@clerk/clerk-js/headless';
22

33
import { createClerkInstance } from './createClerkInstance';
44

5-
/**
6-
* @deprecated Use `getClerkInstance()` instead. `Clerk` will be removed in the next major version.
7-
*/
8-
export { clerk } from './createClerkInstance';
9-
105
/**
116
* Access or create a Clerk instance outside of React. If you are using it in Expo Web then it will only access the existing instance from `window.Clerk`
127
* @example

packages/expo/src/provider/singleton/singleton.web.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ import type { BrowserClerk, HeadlessBrowserClerk } from '@clerk/react';
33
import type { BuildClerkOptions } from './types';
44

55
/**
6-
* @deprecated Use `getClerkInstance()` instead. `Clerk` will be removed in the next major version.
7-
*/
8-
export const clerk = globalThis?.window?.Clerk;
9-
10-
/**
11-
* No need to use options here as we are not creating a new instance of Clerk, we are just getting the existing instance from the window
6+
* Access the existing Clerk instance from `window.Clerk` on the web.
7+
* Unlike the native implementation, this does not create a new instance—it only returns the existing one set by ClerkProvider.
128
*/
139
export const getClerkInstance = (_options?: BuildClerkOptions): HeadlessBrowserClerk | BrowserClerk | undefined =>
1410
globalThis?.window?.Clerk;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: '`Clerk` export removed from `@clerk/expo`'
3+
matcher: "import\\s+\\{[^}]*\\bClerk\\b[^}]*\\}\\s+from\\s+['\"]@clerk/(clerk-)?expo['\"]"
4+
matcherFlags: 'm'
5+
category: 'deprecation-removal'
6+
---
7+
8+
The deprecated `Clerk` export has been removed from `@clerk/expo`. Use `getClerkInstance()` instead.
9+
10+
```diff
11+
- import { Clerk } from '@clerk/clerk-expo';
12+
+ import { getClerkInstance } from '@clerk/expo';
13+
14+
- const token = await Clerk.session?.getToken();
15+
+ const token = await getClerkInstance().session?.getToken();
16+
```
17+
18+
If you need to create the instance before `ClerkProvider` renders, pass the `publishableKey`:
19+
20+
```tsx
21+
import { ClerkProvider, getClerkInstance } from '@clerk/expo';
22+
23+
const clerkInstance = getClerkInstance({ publishableKey: 'pk_xxx' });
24+
25+
// Use the instance outside of React
26+
const token = await clerkInstance.session?.getToken();
27+
```
28+
29+
> [!NOTE]
30+
>
31+
> - Calling `getClerkInstance()` with different publishable keys will create a new Clerk instance.
32+
> - If `getClerkInstance` is called without a publishable key, and `ClerkProvider` has not rendered yet, an error will be thrown.

0 commit comments

Comments
 (0)