getMobileAuthHeaders()
import { getMobileAuthHeaders } from '@auth/clerk'- getMobileAuthHeaders()
Expo (native)
No cookies on native—this helper reads the Clerk session token and returns { Authorization: 'Bearer …' } so your fetch calls can hit a Next.js backend that expects a bearer token.
Usage
fetchers.ts
import { getMobileAuthHeaders } from '@auth/clerk'
export async function fetchProtectedResource() {
const authHeaders = await getMobileAuthHeaders()
const res = await fetch('https://your-api-endpoint.com/protected', {
method: 'GET',
headers: {
...authHeaders,
'Content-Type': 'application/json',
},
})
if (!res.ok) throw new Error('Failed to fetch')
return res.json()
}API
Signature
type AuthHeaders = { Authorization: string }
export declare function getMobileAuthHeaders(): Promise<Partial<AuthHeaders>>Behavior
- On Expo (native): returns
{ Authorization: 'Bearer <token>' }when a session token exists, otherwise{}. - On Web: returns
{}.
For cross-platform data fetching, this util is already integrated into our GraphQL helpers as described in the plugin README.
Last updated on
