Back

Version 12

4/14/2024
/** @jsxImportSource npm:hono/jsx */
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { Hono } from "npm:hono";

const app = new Hono();

const val = extractValInfo(import.meta.url);
const clientID = new URL("/", val.httpEndpoint).toString();
const redirectURI = new URL("/redirect", val.httpEndpoint).toString();

app.get("/", (c) => {
return c.json("OK");
});

app.get("/login", (c) => {
const state = crypto.randomUUID();
// TODO: add state to cookies
return c.html(
<form action="https://pomdtr-indielogin.web.val.run" method="get">
<label for="url">Web Address:</label>
<input id="url" type="text" name="me" placeholder="yourdomain.com" />
<p>
<button type="submit">Sign In</button>
</p>
<input type="hidden" name="client_id" value={clientID} />
<input type="hidden" name="redirect_uri" value={redirectURI} />
<input type="hidden" name="state" value={redirectURI} />
</form>,
);
});

app.get("/redirect", (c) => {
const { code, state } = c.req.query();
const user = fetch("https://pomdtr-indielogin.web.val.run", {
method: "POST",
headers: {
pomdtr-indielogin_example.web.val.run
Updated: April 14, 2024