Created
January 13, 2024 10:52
-
-
Save slvssb/b71cc16ab8f4380c889dbf38beeee8b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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