Spaces:
Sleeping
Sleeping
| 'use client'; | |
| import type { auth } from "@/lib/auth"; | |
| import { inferAdditionalFields } from "better-auth/client/plugins"; | |
| import { createAuthClient } from "better-auth/react"; | |
| import { skipAuth, mockSessionData } from "@/lib/auth-mock"; | |
| const betterAuthUrl = process.env.NEXT_PUBLIC_BETTER_AUTH_URL!; | |
| const authClient = createAuthClient({ | |
| baseURL: betterAuthUrl, | |
| plugins: [inferAdditionalFields<typeof auth>()], | |
| }); | |
| // Mock session for local development when NEXT_PUBLIC_SKIP_AUTH=true | |
| const mockSession = { | |
| data: mockSessionData, | |
| isPending: false, | |
| isRefetching: false, | |
| error: null, | |
| refetch: () => Promise.resolve(), | |
| }; | |
| const mockSignIn = { | |
| social: () => Promise.resolve({ redirect: false, url: '/' }), | |
| } as unknown as typeof authClient.signIn; | |
| const mockSignOut = (() => Promise.resolve({ redirect: false })) as unknown as typeof authClient.signOut; | |
| export const useSession = skipAuth | |
| ? () => mockSession | |
| : authClient.useSession; | |
| export const signIn = skipAuth | |
| ? mockSignIn | |
| : authClient.signIn; | |
| export const signOut = skipAuth | |
| ? mockSignOut | |
| : authClient.signOut; | |