import { socialProviders } from "../../social-provider"; import type { SignInBoxOptions } from "../../store"; export function resolveSvelteKitFiles(options: SignInBoxOptions) { const files = [ { id: "1", name: "auth.ts", content: `import { betterAuth } from "better-auth"; import { sveltekitCookies } from "better-auth/svelte-kit"; import { getRequestEvent } from "$app/server";${ options.socialProviders.length > 0 ? ` import { ${options.socialProviders .map( (provider) => `${provider.toUpperCase()}_CLIENT_ID, ${provider.toUpperCase()}_CLIENT_SECRET`, ) .join("\n\t")} } from "$env/static/private";` : "" }${ options.magicLink ? ` import { magicLink } from "better-auth/plugins/magic-link";` : "" }${ options.passkey ? ` import { passkey } from "@better-auth/passkey";` : "" } export const auth = betterAuth({ ${ options.email ? `emailAndPassword: { enabled: true, ${ options.requestPasswordReset ? `async sendResetPassword(data, request) { // Send an email to the user with a link to reset their password },` : `` } },` : "" }${ options.socialProviders.length ? `socialProviders: ${JSON.stringify( options.socialProviders.reduce( (acc, provider) => ({ ...acc, [provider]: { clientId: `${provider.toUpperCase()}_CLIENT_ID`, clientSecret: `${provider.toUpperCase()}_CLIENT_SECRET`, }, }), {}, ), ).replace(/"/g, "")},` : "" } plugins: [${ options.magicLink ? ` magicLink({ async sendMagicLink(data) { // Send an email to the user with a magic link }, }),` : "" }${ options.passkey ? ` passkey(),` : "" } sveltekitCookies(getRequestEvent), ], /** if no database is provided, the user data will be stored in memory. * Make sure to provide a database to persist user data **/ }); `, }, { id: "2", name: "auth-client.ts", content: `import { createAuthClient } from "better-auth/svelte"; import { PUBLIC_APP_URL } from "$env/static/public";${ options.magicLink ? ` import { magicLinkClient } from "better-auth/client/plugins";` : "" }${ options.passkey ? ` import { passkeyClient } from "@better-auth/passkey/client";` : "" } export const authClient = createAuthClient({ baseURL: PUBLIC_APP_URL,${ options.magicLink || options.passkey ? ` plugins: [${options.magicLink ? `magicLinkClient()${options.passkey ? "," : ""}` : ""}${ options.passkey ? `passkeyClient()` : "" }],` : "" } }); export const { signIn, signOut, signUp, useSession } = authClient; `, }, { id: "3", name: "sign-in.svelte", content: signInString(options), }, ]; if (options.signUp) { files.push({ id: "4", name: "sign-up.svelte", content: signUpString(options), }); } return files; } const signInString = (options: SignInBoxOptions) => ` Sign In Enter your email below to login to your account
${ options.email ? `
${ options.requestPasswordReset ? ` Forgot your password? ` : "" }
${ options.rememberMe ? `
` : "" }` : "" }${ options.magicLink ? `
` : "" }${ options.email ? ` ` : "" }${ options.passkey ? ` ` : "" }${ options.socialProviders?.length > 0 ? `
3 ? '"justify-between flex-wrap"' : '"justify-between flex-col"' } )}> ${options.socialProviders .map((provider: string) => { const icon = socialProviders[provider as keyof typeof socialProviders] ?.stringIcon || ""; return ``; }) .join("\n\t\t\t\t")}
` : "" }
${ options.label ? `

built with  better-auth.

` : "" }
`; const signUpString = (options: SignInBoxOptions) => ` Sign Up Enter your information to create an account
{#if imagePreview}
Profile preview
								class=
{/if}
{#if imagePreview} { image = null; imagePreview = null; }} /> {/if}
${ options.label ? `

Secured by better-auth.

` : "" }
`;