Spaces:
Paused
Paused
Download src/lib/utils/auth.ts from Mike0021/chat-ui-agent-demo: direct link, hf CLI and curl.
- Browser
- Download file 504 Bytes
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/utils/auth.ts
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-demo/src/lib/utils/auth.ts
-
curl -L -o auth.ts https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/utils/auth.ts
504 Bytes
| import { goto } from "$app/navigation"; | |
| import { base } from "$app/paths"; | |
| import { page } from "$app/state"; | |
| /** | |
| * Redirects to the login page if the user is not authenticated | |
| * and the login feature is enabled. | |
| */ | |
| export function requireAuthUser(): boolean { | |
| if (page.data.loginEnabled && !page.data.user) { | |
| const next = page.url.pathname + page.url.search; | |
| const url = `${base}/login?next=${encodeURIComponent(next)}`; | |
| goto(url, { invalidateAll: true }); | |
| return true; | |
| } | |
| return false; | |
| } | |