Skip to Content
Senri

Basic and Bearer auth

Protect routes with a user name and password, or a token, with basicAuth() and bearerAuth()

import { , ,  } from "@senrijs/senri";
declare const : { : string; : string };

const  = ();

.("/admin", ({ : "admin", : . }));
.("/api", ({ : . }));
  • If a request does not pass, the response is 401 with WWW-Authenticate
  • Values are compared in constant time
  • Read passwords and tokens from environment variables or c.env, not from the code
  • With cors(), register cors() first

Check it yourself

Instead of fixed values, check with a function. The request passes only when it returns true.

.("/admin", ({ : (, ) => (, ) }));
.("/api", ({ : () => () }));

Options

Prop

Type

Prop

Type

On this page