Files
nadir-webui/src/lib/auth/client.ts
T
2026-06-22 17:47:16 +02:00

32 lines
726 B
TypeScript

import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
import { page } from '$app/state';
import { env } from '$env/dynamic/public';
import { createAuthClient } from 'better-auth/client';
import {
adminClient,
genericOAuthClient,
inferAdditionalFields,
twoFactorClient,
usernameClient
} from 'better-auth/client/plugins';
export const getAuthClient = () =>
createAuthClient({
baseURL: env.PUBLIC_ORIGIN,
fetchOptions: {
customFetchImpl: page.data.fetch
},
plugins: [
adminClient(),
genericOAuthClient(),
twoFactorClient({
onTwoFactorRedirect: async () => {
await goto(resolve('/auth/2fa'));
}
}),
usernameClient(),
inferAdditionalFields<Auth>()
]
});