I am trying to build a site with svelte-kit that has a small admin section that only users with a username and password can access. What I have right now is an admin page admin.svelte and a page endpoint admin.ts which should return a 401 status with a www-authenticate: basic header when the user is not logged in, like so:
import type { RequestHandler } from '@sveltejs/kit';
export const get: RequestHandler = async () => {
return {
status: 401,
headers: {
'www-authenticate': 'Basic'
}
};
};
But when I open /admin the browser login prompt is not shown like I would expect with the authenticate header. When I look at the network traffic, I can see that the page request has the correct 401 status, but the authenticate header is missing from the response headers.
Contrary to that, the browser login prompt is shown when I navigate via client-side routing from / to /admin.
How can I get the server-rendered page to include authenticate header and show me the browser login prompt, like it does after client side navigation?