mezo
mezo
Explore posts from servers
BABetter Auth
Created by mezo on 4/17/2025 in #help
set a default redirect URL
im hosting my auth layer on a cf worker, and my nextjs on another worker. is there a way to set the redirect to always be on the nextjs worker? i dont wanna do callbackURL: "http://my.nextjs.app/" for all my calls
2 replies
BABetter Auth
Created by mezo on 4/15/2025 in #help
cli not generating migration files due to cf bindings usage
im trying to set up better auth on cf workers (currently with hono, but would switch once this i would find a fix for this). i have the following betterauth config:
// auth.ts
import { betterAuth } from "better-auth";
import { z } from "zod";

export const createAuth = (env: Env) =>
betterAuth({
basePath: "/api/auth",
database: env.AUTH_DB,
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
user: {
additionalFields: {
role: {
type: "string",
validator: {
input: z.enum(["guest", "user", "admin"]).default("guest"),
},
},
active: {
type: "boolean",
validator: {
input: z.boolean(),
},
defaultValue: false,
},
},
},
});
// auth.ts
import { betterAuth } from "better-auth";
import { z } from "zod";

export const createAuth = (env: Env) =>
betterAuth({
basePath: "/api/auth",
database: env.AUTH_DB,
socialProviders: {
google: {
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
},
},
user: {
additionalFields: {
role: {
type: "string",
validator: {
input: z.enum(["guest", "user", "admin"]).default("guest"),
},
},
active: {
type: "boolean",
validator: {
input: z.boolean(),
},
defaultValue: false,
},
},
},
});
it has to be a function as i need to pass the cf env in somehow. this is where the client is created:
// index.ts
import { Hono } from "hono";
import { cors } from "hono/cors";
import { createAuth } from "./auth";

const app = new Hono<{ Bindings: Env }>();

app.use("/api/auth/*", async (c, next) => {
const corsMiddlewareHandler = cors({
origin: c.env.ALLOWED_ORIGIN,
allowHeaders: ["Content-Type", "Authorization"],
allowMethods: ["POST", "GET", "OPTIONS"],
exposeHeaders: ["Content-Length"],
maxAge: 600,
credentials: true,
});
return corsMiddlewareHandler(c, next);
});

app.on(["POST", "GET"], "/api/auth/*", (c) => {
return createAuth(c.env).handler(c.req.raw);
});

export default app satisfies ExportedHandler<Env>;
// index.ts
import { Hono } from "hono";
import { cors } from "hono/cors";
import { createAuth } from "./auth";

const app = new Hono<{ Bindings: Env }>();

app.use("/api/auth/*", async (c, next) => {
const corsMiddlewareHandler = cors({
origin: c.env.ALLOWED_ORIGIN,
allowHeaders: ["Content-Type", "Authorization"],
allowMethods: ["POST", "GET", "OPTIONS"],
exposeHeaders: ["Content-Length"],
maxAge: 600,
credentials: true,
});
return corsMiddlewareHandler(c, next);
});

app.on(["POST", "GET"], "/api/auth/*", (c) => {
return createAuth(c.env).handler(c.req.raw);
});

export default app satisfies ExportedHandler<Env>;
has anyone experienced this aswell before? im aware that the cli is trying to look for a config exported under the name auth, but under my circumstances it's simply just not possible
19 replies
TTCTheo's Typesafe Cult
Created by mezo on 3/4/2025 in #questions
nextjs / trpc as backend vs dedicated backend
maybe a bit better to ask here hehe: i had been wondering about this for a while, but when do you guys usually decide that trpc / server actions / nextjs api routes are just not enough and move off to a separate backend?
8 replies