diff options
| author | diogo464 <[email protected]> | 2025-08-13 16:34:34 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-13 16:34:34 +0100 |
| commit | 817d5696ec6dfe7679467f05619d58b8d741230d (patch) | |
| tree | 24a2cb10369eaa6660773bfa2a7bb1b29bd9c9d2 /frontend/lib/auth_shared.ts | |
| parent | fe27e88eff20b342ba54e8df34ee962d62233552 (diff) | |
refactor: split auth module into separate files and fix imports
- Created auth_types.ts for type definitions
- Created auth_shared.ts for utility functions and endpoints
- Updated auth.ts to focus on session management
- Fixed all auth import statements throughout codebase
- Updated login redirect to use Auth_tinyauth_public_endpoint properly
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Diffstat (limited to 'frontend/lib/auth_shared.ts')
| -rw-r--r-- | frontend/lib/auth_shared.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/frontend/lib/auth_shared.ts b/frontend/lib/auth_shared.ts new file mode 100644 index 0000000..b23b046 --- /dev/null +++ b/frontend/lib/auth_shared.ts | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | import { Env_is_development } from './env'; | ||
| 2 | import type { UserAuth } from './auth_types'; | ||
| 3 | |||
| 4 | export function Auth_user_can_upload(user: UserAuth): boolean { | ||
| 5 | if (!user.isLoggedIn) | ||
| 6 | return false; | ||
| 7 | |||
| 8 | if (Env_is_development()) | ||
| 9 | return true; | ||
| 10 | |||
| 11 | return user.oauth && user.email.endsWith("@campus.fct.unl.pt"); | ||
| 12 | } | ||
| 13 | |||
| 14 | export function Auth_tinyauth_endpoint(): string { | ||
| 15 | const endpoint = process.env.TINYAUTH_ENDPOINT; | ||
| 16 | if (endpoint == undefined) | ||
| 17 | throw new Error(`env var TINYAUTH_ENDPOINT not defined`); | ||
| 18 | return endpoint; | ||
| 19 | } | ||
| 20 | |||
| 21 | export function Auth_tinyauth_public_endpoint(): string { | ||
| 22 | const endpoint = process.env.TINYAUTH_PUBLIC_ENDPOINT; | ||
| 23 | if (endpoint == undefined) | ||
| 24 | throw new Error(`env var TINYAUTH_PUBLIC_ENDPOINT not defined`); | ||
| 25 | return endpoint; | ||
| 26 | } | ||
