Skip to content

Instantly share code, notes, and snippets.

@slvssb
Created January 13, 2024 10:52
Show Gist options
  • Save slvssb/b71cc16ab8f4380c889dbf38beeee8b4 to your computer and use it in GitHub Desktop.
Save slvssb/b71cc16ab8f4380c889dbf38beeee8b4 to your computer and use it in GitHub Desktop.
import AsyncStorage from "@react-native-async-storage/async-storage"
import { hc, type AppType } from "api"
import * as configs from "~/configs/keys"
export const rpcClient = hc<AppType>(process.env.EXPO_PUBLIC_API_URL, {
async fetch(input, requestInit, _Env, _executionCtx) {
const token = await AsyncStorage.getItem(configs.API_KEY_STORAGE)
const headers = new Headers(requestInit?.headers)
headers.append("Authorization", `Bearer ${token}`)
const requestInitExtended = Object.assign(requestInit ?? {}, { headers })
return fetch(input, requestInitExtended)
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment