import { Hono } from "hono"; import { createATProtoOAuth } from "@tijs/atproto-oauth"; import { MemoryStorage } from "@tijs/atproto-storage"; import { LoginForm, SiteLayout } from "./components.tsx"; const app = new Hono(); export const oauth = createATProtoOAuth({ baseUrl: Deno.env.get("BASE_URL")!, appName: "Pedro", cookieSecret: Deno.env.get("COOKIE_SECRET")!, storage: new MemoryStorage(), sessionTtl: 60 * 60 * 24 * 14, // 14 days }); app.get("/login", (c) => oauth.handleLogin(c.req.raw)); app.get("/oauth/callback", (c) => oauth.handleCallback(c.req.raw)); app.get("/oauth-client-metadata.json", () => oauth.handleClientMetadata()); app.post("/api/auth/logout", async (c) => { const res = await oauth.handleLogout(c.req.raw) const { success } = await res.json(); if (success) { return c.html() } else { return c.html(

Error: Logout unsuccessful

) } }); // Routes app.get("/", (c) => { return c.html(

Pedro

Ask questions, share opinions, vote together

) }); app.get("/new", (c) => { return c.html(

Create a new question

) }); // Protected route example app.get("/profile", async (c) => { const { session, error } = await oauth.getSessionFromRequest( c.req.raw, ); if (!session || error) { return c.html(

No profile logged in

) } return c.html(

PDS: {session.pdsUrl}

DID: {session.did}

); }); Deno.serve(app.fetch);