Replies: 1 comment
-
You can check credentials inside a handler and return a 401 response with a WWW-Authenticate header if they are invalid: import { Handlers } from "$fresh/server.ts";
const USER = "alice"
const PASSWORD = "secret"
export const handler: Handlers = {
GET(req) {
if (req.headers.get("Authorization") !== `Basic ${btoa(`${USER}:${PASSWORD}`)}`) {
const headers = new Headers({
"WWW-Authenticate": 'Basic realm="Fake Realm"',
});
return new Response("Unauthorized", { status: 401, headers });
}
return new Response("Fresh is awesome!");
},
}; Hope it helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to do basic authentication?
I would like to implement basic authentication and use it privately.
Beta Was this translation helpful? Give feedback.
All reactions