Back

Version 29

9/2/2024
/** @jsxImportSource npm:hono/jsx **/
import { ValTownAdapter } from "https://esm.town/v/yawnxyz/lucia_adapter_valtown";
import { createUser, getUser, verifyPassword } from "https://esm.town/v/yawnxyz/lucia_sqlite";
import { Hono } from "npm:hono";
import { getCookie } from "npm:hono/cookie";
import { HTTPException } from "npm:hono/http-exception";
import { jsxRenderer } from "npm:hono/jsx-renderer";
import { Lucia, Session, User, verifyRequestOrigin } from "npm:lucia@3.0.1";
import { createDate, isWithinExpirationDate, TimeSpan } from "npm:oslo";

// TODO - make these configurable
const userTable = "lucia_users_1";
const sessionTable = "lucia_sessions_1";

const adapter = new ValTownAdapter({ userTable, sessionTable });


// adding Github Oauth support
import { generateId } from "npm:lucia@3.0.1"; // somehow generateIdFromEntropySize doesn't exist in npm:lucia
import { generateState, OAuth2RequestError, GitHub } from "npm:arctic";
import { serializeCookie, parseCookies } from "npm:oslo/cookie";
const clientId = Deno.env.get("GITHUB_OAUTH_COVERSHEET_CLIENT");
const clientSecret = Deno.env.get("GITHUB_OAUTH_COVERSHEET_SECRET");
export const github = new GitHub(clientId, clientSecret);



export const lucia = new Lucia(adapter, {
sessionCookie: {
attributes: {
sameSite: "none",
},
},
getUserAttributes: (attributes) => {
return {
githubId: attributes.github_id,
Updated: September 3, 2024