mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-04 21:36:39 -05:00
* feat: add cloudflare worker basic tests * chore: fix conflict --------- Co-authored-by: Bereket Engida <bekacru@gmail.com>
28 lines
631 B
TypeScript
28 lines
631 B
TypeScript
import { Hono } from "hono";
|
|
import { Auth, createAuth } from "./auth";
|
|
|
|
const app = new Hono<{
|
|
Bindings: CloudflareBindings;
|
|
Variables: {
|
|
auth: Auth;
|
|
};
|
|
}>();
|
|
|
|
app.use("*", async (c, next) => {
|
|
const auth = createAuth(c.env);
|
|
c.set("auth", auth);
|
|
await next();
|
|
});
|
|
|
|
app.on(["POST", "GET"], "/api/auth/*", (c) => c.var.auth.handler(c.req.raw));
|
|
|
|
app.get("/", async (c) => {
|
|
const session = await c.var.auth.api.getSession({
|
|
headers: c.req.raw.headers,
|
|
});
|
|
if (session) return c.text("Hello " + session.user.name);
|
|
return c.text("Not logged in");
|
|
});
|
|
|
|
export default app satisfies ExportedHandler<CloudflareBindings>;
|