Files
Zero/apps/mail/lib/auth-proxy.ts
2025-05-20 13:56:47 +05:30

24 lines
684 B
TypeScript

import { customSessionClient } from 'better-auth/client/plugins';
import { createAuthClient } from 'better-auth/client';
import type { Auth } from '@zero/server/auth';
const authClient = createAuthClient({
baseURL: import.meta.env.VITE_PUBLIC_BACKEND_URL,
fetchOptions: {
credentials: 'include',
},
plugins: [customSessionClient<Auth>()],
});
export const authProxy = {
api: {
getSession: async ({ headers }: { headers: Headers }) => {
const session = await authClient.getSession({
fetchOptions: { headers, credentials: 'include' },
});
if (session.error) throw new Error(session.error.message);
return session.data;
},
},
};