Skip to content

Commit

Permalink
fix(clerk-expo): Ensure correct mobile detection for native requests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano authored Sep 10, 2024
1 parent 4020ead commit da01be9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-donuts-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/clerk-expo": patch
---

Fixes an issue where iOS session activities were incorrectly classified as non-mobile
8 changes: 8 additions & 0 deletions packages/expo/src/provider/singleton/createClerkInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { BrowserClerk, HeadlessBrowserClerk } from '@clerk/clerk-react';

import { MemoryTokenCache } from '../../cache/MemoryTokenCache';
import { errorThrower } from '../../errorThrower';
import { isNative } from '../../utils';
import type { BuildClerkOptions } from './types';

const KEY = '__clerk_client_jwt';
Expand Down Expand Up @@ -42,10 +43,17 @@ export function createClerkInstance(ClerkClass: typeof Clerk) {
// https://reactnative.dev/docs/0.61/network#known-issues-with-fetch-and-cookie-based-authentication
requestInit.credentials = 'omit';

// Instructs the backend to parse the api token from the Authorization header.
requestInit.url?.searchParams.append('_is_native', '1');

const jwt = await getToken(KEY);
(requestInit.headers as Headers).set('authorization', jwt || '');

// Instructs the backend that the request is from a mobile device.
// Some iOS devices have an empty user-agent, so we can't rely on that.
if (isNative()) {
(requestInit.headers as Headers).set('x-mobile', '1');
}
});

// @ts-expect-error - This is an internal API
Expand Down

0 comments on commit da01be9

Please sign in to comment.