Skip to content

Commit cb4ff0e

Browse files
committed
chore(expo): Remove Clerk instance export
1 parent e76d248 commit cb4ff0e

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

.changeset/tame-carpets-sink.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
'@clerk/expo': major
3+
---
4+
5+
Remove deprecated `Clerk` export in favor of `getClerkInstance()`.
6+
7+
Before:
8+
9+
```tsx
10+
import { Clerk } from '@clerk/expo';
11+
12+
// Access the Clerk instance
13+
const token = await Clerk.session?.getToken();
14+
```
15+
16+
After:
17+
18+
```tsx
19+
import { getClerkInstance } from '@clerk/expo';
20+
21+
// Access the Clerk instance
22+
const token = await getClerkInstance().session?.getToken();
23+
```
24+
25+
If you need to create the instance before `ClerkProvider` renders, pass the `publishableKey`:
26+
27+
```tsx
28+
import { ClerkProvider, getClerkInstance } from '@clerk/expo';
29+
30+
const clerkInstance = getClerkInstance({ publishableKey: 'pk_xxx' });
31+
32+
// Use the instance outside of React
33+
const token = await clerkInstance.session?.getToken();
34+
fetch('https://example.com/api', { headers: { Authorization: `Bearer ${token}` } });
35+
```
36+
37+
> [!NOTE]
38+
> - Calling `getClerkInstance()` with different publishable keys will create a new Clerk instance.
39+
> - 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;

0 commit comments

Comments
 (0)