14c880123c
Expo app with dashboard, time clock, invoices, and settings — native tabs, glass UI, theme-aware components, and iOS Live Activities. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { expoClient } from "@better-auth/expo/client";
|
|
import { createAuthClient } from "better-auth/react";
|
|
import * as SecureStore from "expo-secure-store";
|
|
import {
|
|
createContext,
|
|
useContext,
|
|
useMemo,
|
|
type ReactNode,
|
|
} from "react";
|
|
|
|
type AuthClient = ReturnType<typeof createAuthClient>;
|
|
|
|
const AuthContext = createContext<AuthClient | null>(null);
|
|
|
|
export function AuthProvider({
|
|
apiUrl,
|
|
storagePrefix,
|
|
children,
|
|
}: {
|
|
apiUrl: string;
|
|
storagePrefix: string;
|
|
children: ReactNode;
|
|
}) {
|
|
const client = useMemo(
|
|
() =>
|
|
createAuthClient({
|
|
baseURL: apiUrl,
|
|
plugins: [
|
|
expoClient({
|
|
scheme: "beenvoice",
|
|
storagePrefix,
|
|
storage: SecureStore,
|
|
}),
|
|
],
|
|
}),
|
|
[apiUrl, storagePrefix],
|
|
);
|
|
|
|
return <AuthContext.Provider value={client}>{children}</AuthContext.Provider>;
|
|
}
|
|
|
|
export function useAuthClient() {
|
|
const client = useContext(AuthContext);
|
|
if (!client) throw new Error("useAuthClient must be used within AuthProvider");
|
|
return client;
|
|
}
|
|
|
|
export function useSession() {
|
|
return useAuthClient().useSession();
|
|
}
|