diff options
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 | } | ||
