fix(expo): local session cache should be scopped (#1020)

This commit is contained in:
Bereket Engida
2024-12-26 18:44:16 +03:00
committed by GitHub
parent 8b14725c84
commit ef2ff4ce56
5 changed files with 17 additions and 19 deletions
@@ -5,7 +5,6 @@ import Constants from "expo-constants";
export const getBaseUrl = () => {
const debuggerHost = Constants.expoConfig?.hostUri;
const localhost = debuggerHost?.split(":")[0];
return `http://${"localhost"}:8081`;
};
+1
View File
@@ -16,4 +16,5 @@ export const auth = betterAuth({
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
},
},
trustedOrigins: ["exp://"],
});
@@ -102,3 +102,5 @@ export function createAuthClient<Option extends ClientOptions>(
export type * from "@better-fetch/fetch";
//@ts-expect-error
export type * from "zod";
export { useStore };
+14 -10
View File
@@ -2,6 +2,7 @@ import type { BetterAuthClientPlugin, Store } from "better-auth";
import * as Browser from "expo-web-browser";
import * as Linking from "expo-linking";
import { Platform } from "react-native";
import { useStore } from "better-auth/react";
import Constants from "expo-constants";
import type { BetterFetchOption } from "@better-fetch/fetch";
@@ -108,16 +109,6 @@ export const expoClient = (opts: ExpoClientOptions) => {
return {
id: "expo",
getActions(_, $store) {
if (Platform.OS !== "web") {
store = $store;
const localSession = storage.getItem(cookieName);
localSession &&
$store.atoms.session.set({
data: JSON.parse(localSession),
error: null,
isPending: false,
});
}
return {
/**
* Get the stored cookie.
@@ -138,6 +129,19 @@ export const expoClient = (opts: ExpoClientOptions) => {
const cookie = storage.getItem(cookieName);
return getCookie(cookie || "{}");
},
useSession: () => {
if (Platform.OS !== "web" && !opts.disableCache) {
store = $store;
const localSession = storage.getItem(localCacheName);
localSession &&
$store.atoms.session.set({
data: JSON.parse(localSession),
error: null,
isPending: false,
});
}
return useStore($store.atoms.session);
},
};
},
fetchPlugins: [
-8
View File
@@ -42,14 +42,6 @@ vi.mock("expo-linking", async () => {
};
});
vi.mock("expo-secure-store", async () => {
return {
getItemAsync: vi.fn(async (key) => null),
setItemAsync: vi.fn(),
deleteItemAsync: vi.fn(),
};
});
const fn = vi.fn();
describe("expo", async () => {