UNPKG

@reliverse/rse

Version:

@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power

68 lines (67 loc) 2.17 kB
import fs from "@reliverse/relifso"; import { relinka } from "@reliverse/relinka"; import path from "node:path"; import { addPackageDependency } from "../../utils/add-package-deps.js"; export async function setupAuth(config) { const { auth, frontend, backend, projectDir } = config; if (backend === "convex" || !auth) { return; } const serverDir = path.join(projectDir, "apps/server"); const clientDir = path.join(projectDir, "apps/web"); const nativeDir = path.join(projectDir, "apps/native"); const clientDirExists = await fs.pathExists(clientDir); const nativeDirExists = await fs.pathExists(nativeDir); const serverDirExists = await fs.pathExists(serverDir); try { if (serverDirExists) { await addPackageDependency({ dependencies: ["better-auth"], projectDir: serverDir }); } const hasWebFrontend = frontend.some( (f) => [ "react-router", "tanstack-router", "tanstack-start", "next", "nuxt", "svelte", "solid" ].includes(f) ); if (hasWebFrontend && clientDirExists) { await addPackageDependency({ dependencies: ["better-auth"], projectDir: clientDir }); } if ((frontend.includes("native-nativewind") || frontend.includes("native-unistyles")) && nativeDirExists) { await addPackageDependency({ dependencies: ["better-auth", "@better-auth/expo"], projectDir: nativeDir }); if (serverDirExists) { await addPackageDependency({ dependencies: ["@better-auth/expo"], projectDir: serverDir }); } } } catch (error) { relinka("error", "Failed to configure authentication dependencies"); if (error instanceof Error) { relinka("error", error.message); } } } export function generateAuthSecret(length = 32) { const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let result = ""; const charactersLength = characters.length; for (let i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; }