Skip to content

Commit

Permalink
feat(mobile): add x-device-language to hono headers (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev authored Aug 2, 2024
1 parent 86c99bd commit fbfb599
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions apps/mobile/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppType } from '@6pm/api'
import { getClerkInstance } from '@clerk/clerk-expo'
import { QueryClient } from '@tanstack/react-query'
import { getLocales } from 'expo-localization'
import { hc } from 'hono/client'
import { tokenCache } from './cache'

Expand All @@ -11,11 +12,20 @@ export const clerk = getClerkInstance({

export const getHonoClient = async () => {
const token = await clerk.session?.getToken()
const deviceLanguage = getLocales()[0].languageCode

const headers: Record<string, string> = {}

if (token) {
headers.Authorization = `Bearer ${token}`
}

if (deviceLanguage) {
headers['x-device-language'] = deviceLanguage
}

return hc<AppType>(process.env.EXPO_PUBLIC_API_URL!, {
headers: {
// biome-ignore lint/style/useNamingConvention: <explanation>
Authorization: `Bearer ${token}`,
},
headers,
})
}

Expand Down

0 comments on commit fbfb599

Please sign in to comment.