| 1 | export 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 | |
| 9 | export function loginUrl (returnTo = location.pathname + location.search) |
| 10 | { |
| 11 | return `/auth/login?return_to=${encodeURIComponent(returnTo)}`; |
| 12 | } |
| 13 | |
| 14 | export function logoutUrl (returnTo = "/") |
| 15 | { |
| 16 | return `/auth/logout?return_to=${encodeURIComponent(returnTo)}`; |
| 17 | } |
| 18 | |
| 19 | export 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 | } |