mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-19 23:53:17 -05:00
fix(expo): local session cache should be scopped (#1020)
This commit is contained in:
@@ -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`;
|
||||
};
|
||||
|
||||
|
||||
@@ -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
@@ -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: [
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user