Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Button Link

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* @title Password Authentication
* @description Protect your vals behind a password
* @resource [Password Auth Val](https://esm.town/v/pomdtr/password_auth)
* @preview https://pomdtr-password_auth_example.web.val.run
*/
import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth";
// This is the server I want to protect.
const server = () => {
return new Response("You're authenticated!");
};
// Your password should be stored in an env var.
// For this example, the password is val_town_is_awesome.
const password = Deno.env.get("EXAMPLE_PASSWORD");
// We can add authentication by simply wrapping the server in the passwordAuth middleware.
// If you don't set the password option, you can still use a val.town token to authenticate.
export default passwordAuth(server, { password: password });
pomdtr-password_auth_example.web.val.run
April 10, 2024