Lastlogin Authentication for val.town
Looking for an hono integration ? See @pomdtr/lastloginHono
Support login in trough:
- Email Link
- QR Code
- Google Oauth
- Github Oauth
- Gitlab Oauth
- Facebook Oauth
You can try a demo at https://pomdtr-lastloginhonoexample.web.val.run (see @pomdtr/lastLoginHonoExample for code)
Wrap your http handlers in a lastlogin middleware (sessions will be persisted in the lastlogin_session
table on your sqlite account).
If you want to be the only one able to access your val, you can use @pomdtr/verifyUserEmail.
import { lastlogin }
from "https://esm.town/v/pomdtr/lastlogin";
import { verifyUserEmail }
from "https://esm.town/v/pomdtr/verifyUserEmail";
export default lastlogin(
(req) => {
return new Response(
`You are logged in as ${req.headers.get("X-LastLogin-Email")}`);
}, {
verifyEmail: verifyUserEmail
});
If you want to customize how is allowed to signup, you can set the verifyEmail option:
import { lastlogin }
from "https://esm.town/v/pomdtr/lastlogin";
export default lastlogin(
(req) => {
return new Response(
`You are logged in as ${req.headers.get("X-LastLogin-Email")}`);
}, {
verifyEmail:
(email) => { email ==
"steve@valtown" }
});
You can allow anyone to signup by returning a boolean from the verifyEmail function:
import { lastlogin }
from "https://esm.town/v/pomdtr/lastlogin";
export default lastlogin(
(req) => {
return new Response(
`You are logged in as ${req.headers.get("X-LastLogin-Email")}`);
}, {
verifyEmail:
(_email) => true
});
import { lastlogin }
from "https://esm.town/v/pomdtr/lastlogin";
import { verifyUserEmail }
from "https://esm.town/v/pomdtr/verifyUserEmail";
export default lastlogin(
() => {
return new Response(
"Hi!");
}, {
verifyEmail: verifyUserEmail,
public_routes: [
"/",
"/public/*"],
});
See the URLPattern API for reference.
Just redirect the user to /auth/logout