import { socialProviders } from "../../social-provider"; import type { SignInBoxOptions } from "../../store"; export function resolveNuxtFiles(options: SignInBoxOptions) { const files = [ { id: "1", name: "auth.ts", content: `import { betterAuth } from "better-auth";${ 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: `process.env.${provider.toUpperCase()}_CLIENT_ID!`, clientSecret: `process.env.${provider.toUpperCase()}_CLIENT_SECRET!`, }, }), {}, ), ).replace(/"/g, "")},` : "" }${ options.magicLink || options.passkey ? ` plugins: [ ${ options.magicLink ? `magicLink({ async sendMagicLink(data) { // Send an email to the user with a magic link }, }),` : `${options.passkey ? `passkey(),` : ""}` } ${options.passkey && options.magicLink ? `passkey(),` : ""}],` : "" } /** 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/react";${ options.magicLink ? ` import { magicLinkClient } from "better-auth/client/plugins";` : "" }${ options.passkey ? ` import { passkeyClient } from "@better-auth/passkey/client";` : "" } export const authClient = createAuthClient({ baseURL: process.env.NUXT_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.vue", content: signInString(options), }, ]; if (options.signUp) { files.push({ id: "4", name: "sign-up.vue", content: signUpString(options), }); } return files; } const signInString = (options: SignInBoxOptions) => ` `; const signUpString = (options: SignInBoxOptions) => ` `;