Skip to content
Discussion options

You must be logged in to vote

Here's a working Hono + better-auth setup with protected routes:

1. Install dependencies

npm install hono better-auth @better-auth/node

2. Set up better-auth

// src/auth.ts
import { betterAuth } from "better-auth";

export const auth = betterAuth({
  database: {
    provider: "sqlite", // or "pg", "mysql"
    url: "./db.sqlite",
  },
  emailAndPassword: {
    enabled: true,
  },
});

3. Mount better-auth handler in Hono

// src/index.ts
import { Hono } from "hono";
import { cors } from "hono/cors";
import { auth } from "./auth";

const app = new Hono();

// CORS for frontend
app.use(
  "/api/auth/**",
  cors({
    origin: "http://localhost:3001", // your frontend
    allowHeaders: ["Content…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by TangoPJ
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants