UNPKG

@oberoncms/core

Version:

OberonCMS is a cloud deployable CMS written in typescript based on the Puck visual editor

56 lines (55 loc) 1.4 kB
import { betterAuth } from "better-auth"; import { nextCookies } from "better-auth/next-js"; import { emailOTP } from "better-auth/plugins"; const cmsAuthBasePath = "/cms/api/auth"; const noopSendVerificationRequest = async () => { }; function createAuthOptions({ betterAuth: betterAuthAdapter, sendVerificationRequest }) { const baseURL = process.env.BETTER_AUTH_URL; const secret = process.env.AUTH_SECRET; return { ...betterAuthAdapter ? { database: betterAuthAdapter.database } : {}, ...baseURL && { baseURL }, basePath: cmsAuthBasePath, secret, user: { additionalFields: { role: { type: "string", required: true, input: false } } }, plugins: [ emailOTP({ disableSignUp: true, async sendVerificationOTP({ email, otp, type }) { if (type !== "sign-in") { return; } const loginUrl = new URL("/cms/login", "http://localhost"); loginUrl.searchParams.set("email", email); await sendVerificationRequest({ email, token: otp, url: `${loginUrl.pathname}${loginUrl.search}` }); } }), nextCookies() ] }; } betterAuth( createAuthOptions({ sendVerificationRequest: noopSendVerificationRequest }) ); export { cmsAuthBasePath, createAuthOptions };