latest
pomdtr/deno-lastloginlastlogin auth for smallweb
Lastlogin Authentication
Usage in smallweb
First wrap your endpoint in the lastlogin middleware.
// ~/smallweb/lastlogin-example/main.ts import { lastlogin } from "jsr:@pomdtr/lastlogin"; export default { fetch: lastlogin((req: Request) => { const email = req.headers.get("X-Lastlogin-Email"); if (!email) { return new Response("You are not logged in", { status: 401 } ); } return new Response(`Hello, ${email}!`); }), };
By default, routes are not protected behind auth. To protect all routes, you can provide the isProtected option.
// ~/smallweb/lastlogin-example/main.ts import { lastlogin } from "jsr:@pomdtr/lastlogin"; export default { fetch: lastlogin( { // protect all routes behind auth isProtected: true, }, (req: Request) => { const email = req.headers.get("X-Lastlogin-Email"); return new Response(`Hello, ${email}!`); } ), };
You can also provide a function to isProtected to protect only certain routes.
// ~/smallweb/lastlogin-example/main.ts import { lastlogin } from "jsr:@pomdtr/lastlogin"; export default { fetch: lastlogin( { isProtected: (pathname: string) => { return pathname.startsWith("/admin"); }, }, (req: Request) => { const email = req.headers.get("X-Lastlogin-Email"); return new Response(`Hello, ${email}!`); } ), };
If you only want to allow emails from a specific provider (ex: Google), you can provide the provider option.
// ~/smallweb/lastlogin-example/main.ts import { lastlogin } from "jsr:@pomdtr/lastlogin"; export default { fetch: lastlogin({ isProtected: true, provider: "google", }, (req: Request) => { const email = req.headers.get("X-Lastlogin-Email"); return new Response(`Hello, ${email}!`); } ), };
If you want to restrict access to certain emails, you can provide a isAuthorized function.
// ~/smallweb/lastlogin-example/main.ts import { lastlogin } from "jsr:@pomdtr/lastlogin"; export default { fetch: lastlogin({ isProtected: true, verifyEmail: async (email: string) => { return email == "pomdtr@smallweb.run"; } }, (req: Request) => { const email = req.headers.get("X-Lastlogin-Email"); return new Response(`Hello, ${email}!`); }, ), };
Add Package
deno add jsr:@pomdtr/lastlogin
Import symbol
import * as lastlogin from "@pomdtr/lastlogin";
Import directly with a jsr specifier
import * as lastlogin from "jsr:@pomdtr/lastlogin";
Add Package
pnpm i jsr:@pomdtr/lastlogin
pnpm dlx jsr add @pomdtr/lastlogin
Import symbol
import * as lastlogin from "@pomdtr/lastlogin";
Add Package
yarn add jsr:@pomdtr/lastlogin
yarn dlx jsr add @pomdtr/lastlogin
Import symbol
import * as lastlogin from "@pomdtr/lastlogin";
Add Package
vlt install jsr:@pomdtr/lastlogin
Import symbol
import * as lastlogin from "@pomdtr/lastlogin";
Add Package
npx jsr add @pomdtr/lastlogin
Import symbol
import * as lastlogin from "@pomdtr/lastlogin";
Add Package
bunx jsr add @pomdtr/lastlogin
Import symbol
import * as lastlogin from "@pomdtr/lastlogin";