BlueGit

timfa questward

Files

questward / client / src / net / auth.js

auth.js

auth.js 653 B Download Raw
1export async function fetchAuthStatus ()
2{
3 const response = await fetch("/auth/status", { cache: "no-store" });
4 if (!response.ok)
5 { return { authenticated: false }; }
6 return response.json();
7}
8
9export function loginUrl (returnTo = location.pathname + location.search)
10{
11 return `/auth/login?return_to=${encodeURIComponent(returnTo)}`;
12}
13
14export function logoutUrl (returnTo = "/")
15{
16 return `/auth/logout?return_to=${encodeURIComponent(returnTo)}`;
17}
18
19export function formatAccountLabel (status)
20{
21 if (!status?.authenticated)
22 { return "Signed out"; }
23 if (status.username)
24 { return status.username; }
25 return status.authSubject ?? "Signed in";
26}