@poadio/starter-angular 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +9 -0
- package/.env.example +7 -0
- package/Dockerfile +20 -0
- package/README.md +91 -2
- package/angular.json +119 -0
- package/bun.lock +1057 -0
- package/docker/40-env-json.sh +39 -0
- package/docker/nginx.conf +24 -0
- package/package.json +86 -4
- package/public/logo.svg +1 -0
- package/public/providers/google.svg +1 -0
- package/public/providers/keycloak.svg +1 -0
- package/scripts/dev.mjs +30 -0
- package/scripts/env.mjs +96 -0
- package/scripts/routes.mjs +155 -0
- package/src/app/app.config.ts +16 -0
- package/src/app/app.meta.ts +43 -0
- package/src/app/app.routes.gen.ts +7 -0
- package/src/app/app.routes.ts +32 -0
- package/src/app/app.ts +17 -0
- package/src/app/core/auth.service.ts +117 -0
- package/src/app/core/captcha.ts +94 -0
- package/src/app/core/config.ts +17 -0
- package/src/app/core/env.ts +27 -0
- package/src/app/core/guards.ts +33 -0
- package/src/app/core/messages.ts +38 -0
- package/src/app/core/poad.ts +46 -0
- package/src/app/core/providers.ts +32 -0
- package/src/app/core/theme.service.ts +37 -0
- package/src/app/layout/_layout.scss +799 -0
- package/src/app/layout/app-layout.ts +263 -0
- package/src/app/layout/app-menu.ts +68 -0
- package/src/app/layout/app-menuitem.ts +105 -0
- package/src/app/layout/brand.ts +50 -0
- package/src/app/layout/canvas-head.ts +78 -0
- package/src/app/layout/layout.service.ts +159 -0
- package/src/app/pages/(auth)/login.html +128 -0
- package/src/app/pages/(auth)/login.ts +194 -0
- package/src/app/pages/(auth)/mfa.ts +61 -0
- package/src/app/pages/(auth)/reset.ts +53 -0
- package/src/app/pages/app/_layout.ts +5 -0
- package/src/app/pages/app/account.html +233 -0
- package/src/app/pages/app/account.ts +262 -0
- package/src/app/pages/app/hello/[name].ts +35 -0
- package/src/app/pages/app/index.ts +82 -0
- package/src/app/pages/app/public.ts +33 -0
- package/src/app/pages/index.ts +280 -0
- package/src/app/pages/setup.ts +51 -0
- package/src/index.html +13 -0
- package/src/main.ts +9 -0
- package/src/styles.scss +151 -0
- package/tsconfig.app.json +15 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Injectable, computed, inject, signal } from '@angular/core';
|
|
2
|
+
import { Router } from '@angular/router';
|
|
3
|
+
import { CadToastService } from '@cadriciel/ui';
|
|
4
|
+
import {
|
|
5
|
+
decodeJwt,
|
|
6
|
+
type AuthError,
|
|
7
|
+
type AuthEvent,
|
|
8
|
+
type Result,
|
|
9
|
+
type Session,
|
|
10
|
+
type Settings,
|
|
11
|
+
} from '@poadio/client-js';
|
|
12
|
+
import { loadConfig, type PoadConfig } from './config';
|
|
13
|
+
import { authMessage } from './messages';
|
|
14
|
+
import { Poad } from './poad';
|
|
15
|
+
|
|
16
|
+
/** Entrées de /settings qui ne sont pas des fournisseurs OAuth */
|
|
17
|
+
const NOT_OAUTH = new Set(['email', 'phone', 'anonymous_users']);
|
|
18
|
+
|
|
19
|
+
/** Où mène une connexion réussie */
|
|
20
|
+
export const HOME_SIGNED_IN = '/app';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* État d'authentification de l'application, en signaux. Le client lui-même
|
|
24
|
+
* (poad.auth, poad.storage…) est le service Poad (core/poad.ts).
|
|
25
|
+
*/
|
|
26
|
+
@Injectable({ providedIn: 'root' })
|
|
27
|
+
export class AuthService {
|
|
28
|
+
private readonly router = inject(Router);
|
|
29
|
+
private readonly toast = inject(CadToastService);
|
|
30
|
+
|
|
31
|
+
private readonly poad = inject(Poad);
|
|
32
|
+
readonly config = signal<PoadConfig | null>(null);
|
|
33
|
+
readonly settings = signal<Settings | null>(null);
|
|
34
|
+
readonly session = signal<Session | null>(null);
|
|
35
|
+
|
|
36
|
+
readonly user = computed(() => this.session()?.user ?? null);
|
|
37
|
+
readonly claims = computed(() => {
|
|
38
|
+
const s = this.session();
|
|
39
|
+
return s ? decodeJwt(s.access_token) : null;
|
|
40
|
+
});
|
|
41
|
+
/** Nom affiché : métadonnées, sinon adresse, sinon « Invité » (session anonyme) */
|
|
42
|
+
readonly displayName = computed(() => {
|
|
43
|
+
const u = this.user();
|
|
44
|
+
if (!u) return '';
|
|
45
|
+
const meta = u.user_metadata ?? {};
|
|
46
|
+
return (meta['name'] as string) || (meta['full_name'] as string) || u.email || 'Invité';
|
|
47
|
+
});
|
|
48
|
+
/** Un facteur TOTP vérifié existe mais la session n'est qu'en aal1 */
|
|
49
|
+
readonly needsMfa = computed(() => {
|
|
50
|
+
const claims = this.claims();
|
|
51
|
+
if (!claims || claims.aal !== 'aal1') return false;
|
|
52
|
+
return (this.user()?.factors ?? []).some((f) => f.status === 'verified');
|
|
53
|
+
});
|
|
54
|
+
readonly oauthProviders = computed(() =>
|
|
55
|
+
Object.entries(this.settings()?.external ?? {})
|
|
56
|
+
.filter(([name, on]) => on && !NOT_OAUTH.has(name))
|
|
57
|
+
.map(([name]) => name)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
/** Appelé avant la première navigation (provideAppInitializer) */
|
|
61
|
+
async init(): Promise<void> {
|
|
62
|
+
const config = loadConfig();
|
|
63
|
+
this.config.set(config);
|
|
64
|
+
if (!config) return;
|
|
65
|
+
const client = this.poad.connect(config.url, config.anonKey).auth;
|
|
66
|
+
client.onChange((event, session) => {
|
|
67
|
+
this.session.set(session);
|
|
68
|
+
this.route(event);
|
|
69
|
+
});
|
|
70
|
+
// Traite un retour de lien e-mail ou de fournisseur OAuth présent dans l'URL
|
|
71
|
+
await client.ready();
|
|
72
|
+
this.session.set(client.session);
|
|
73
|
+
if (client.urlError) this.toast.error('Connexion refusée', client.urlError.message);
|
|
74
|
+
if (client.urlEvent === 'PASSWORD_RECOVERY') void this.router.navigateByUrl('/reset');
|
|
75
|
+
const s = await client.settings();
|
|
76
|
+
if (s.data) this.settings.set(s.data);
|
|
77
|
+
else this.toast.error('Projet poad injoignable', `${config.url} : ${s.error.message}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Exécute un appel, affiche l'erreur ou le message de succès, renvoie les données */
|
|
81
|
+
async run<T>(call: () => Promise<Result<T>>, success?: string): Promise<T | null> {
|
|
82
|
+
const r = await call();
|
|
83
|
+
if (r.error) {
|
|
84
|
+
this.fail(r.error);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (success) this.toast.success(success);
|
|
88
|
+
return r.data;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fail(error: AuthError): void {
|
|
92
|
+
const { title, detail } = authMessage(error);
|
|
93
|
+
this.toast.error(title, detail);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Adresse de retour des e-mails et des fournisseurs OAuth */
|
|
97
|
+
redirect(path = '/'): string {
|
|
98
|
+
return new URL(path, window.location.origin).toString();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
signOut(): void {
|
|
102
|
+
void this.run(() => this.poad.auth.signOut());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private route(event: AuthEvent): void {
|
|
106
|
+
const url = this.router.url;
|
|
107
|
+
if (event === 'SIGNED_OUT') void this.router.navigateByUrl('/');
|
|
108
|
+
else if (event === 'PASSWORD_RECOVERY') void this.router.navigateByUrl('/reset');
|
|
109
|
+
else if (event === 'SIGNED_IN' && (url.startsWith('/login') || url === '/')) {
|
|
110
|
+
// Retour vers la page demandée avant la connexion (?next=), si elle est locale
|
|
111
|
+
const next = new URL(url, window.location.origin).searchParams.get('next');
|
|
112
|
+
const target = next && next.startsWith('/') && !next.startsWith('//') ? next : HOME_SIGNED_IN;
|
|
113
|
+
void this.router.navigateByUrl(this.needsMfa() ? '/mfa' : target);
|
|
114
|
+
}
|
|
115
|
+
else if (event === 'MFA_VERIFIED' && url.startsWith('/mfa')) void this.router.navigateByUrl(HOME_SIGNED_IN);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Component, ElementRef, OnDestroy, effect, input, output, viewChild } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
type Provider = 'hcaptcha' | 'turnstile';
|
|
4
|
+
|
|
5
|
+
interface WidgetApi {
|
|
6
|
+
render(el: HTMLElement, options: Record<string, unknown>): string;
|
|
7
|
+
reset(id?: string): void;
|
|
8
|
+
remove?(id: string): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const SCRIPTS: Record<Provider, { src: string; global: string }> = {
|
|
12
|
+
turnstile: { src: 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit', global: 'turnstile' },
|
|
13
|
+
hcaptcha: { src: 'https://js.hcaptcha.com/1/api.js?render=explicit', global: 'hcaptcha' },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const loading = new Map<Provider, Promise<WidgetApi>>();
|
|
17
|
+
|
|
18
|
+
/** Charge une seule fois le script du fournisseur */
|
|
19
|
+
function load(provider: Provider): Promise<WidgetApi> {
|
|
20
|
+
let p = loading.get(provider);
|
|
21
|
+
if (!p) {
|
|
22
|
+
const { src, global } = SCRIPTS[provider];
|
|
23
|
+
p = new Promise<WidgetApi>((resolve, reject) => {
|
|
24
|
+
const existing = (window as unknown as Record<string, WidgetApi | undefined>)[global];
|
|
25
|
+
if (existing) return resolve(existing);
|
|
26
|
+
const script = document.createElement('script');
|
|
27
|
+
script.src = src;
|
|
28
|
+
script.async = true;
|
|
29
|
+
script.onload = () => {
|
|
30
|
+
const api = (window as unknown as Record<string, WidgetApi | undefined>)[global];
|
|
31
|
+
api ? resolve(api) : reject(new Error(`${provider} non disponible`));
|
|
32
|
+
};
|
|
33
|
+
script.onerror = () => {
|
|
34
|
+
loading.delete(provider);
|
|
35
|
+
reject(new Error(`Impossible de charger ${provider}`));
|
|
36
|
+
};
|
|
37
|
+
document.head.appendChild(script);
|
|
38
|
+
});
|
|
39
|
+
loading.set(provider, p);
|
|
40
|
+
}
|
|
41
|
+
return p;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Widget CAPTCHA (Turnstile ou hCaptcha) : émet le jeton à passer en
|
|
46
|
+
* captchaToken. Un jeton ne sert qu'une fois : appeler reset() après chaque
|
|
47
|
+
* envoi.
|
|
48
|
+
*/
|
|
49
|
+
@Component({
|
|
50
|
+
selector: 'app-captcha',
|
|
51
|
+
template: `<div #host></div>`,
|
|
52
|
+
styles: `
|
|
53
|
+
:host {
|
|
54
|
+
display: block;
|
|
55
|
+
min-height: 65px;
|
|
56
|
+
}
|
|
57
|
+
`,
|
|
58
|
+
})
|
|
59
|
+
export class CaptchaComponent implements OnDestroy {
|
|
60
|
+
readonly provider = input.required<Provider>();
|
|
61
|
+
readonly siteKey = input.required<string>();
|
|
62
|
+
readonly token = output<string | null>();
|
|
63
|
+
|
|
64
|
+
private readonly host = viewChild.required<ElementRef<HTMLElement>>('host');
|
|
65
|
+
private api: WidgetApi | null = null;
|
|
66
|
+
private id: string | null = null;
|
|
67
|
+
|
|
68
|
+
constructor() {
|
|
69
|
+
effect(() => {
|
|
70
|
+
const provider = this.provider();
|
|
71
|
+
const siteKey = this.siteKey();
|
|
72
|
+
const el = this.host().nativeElement;
|
|
73
|
+
void load(provider).then((api) => {
|
|
74
|
+
this.api = api;
|
|
75
|
+
el.innerHTML = '';
|
|
76
|
+
this.id = api.render(el, {
|
|
77
|
+
sitekey: siteKey,
|
|
78
|
+
callback: (t: string) => this.token.emit(t),
|
|
79
|
+
'expired-callback': () => this.token.emit(null),
|
|
80
|
+
'error-callback': () => this.token.emit(null),
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
reset(): void {
|
|
87
|
+
this.token.emit(null);
|
|
88
|
+
if (this.api && this.id !== null) this.api.reset(this.id);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ngOnDestroy(): void {
|
|
92
|
+
if (this.api?.remove && this.id !== null) this.api.remove(this.id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { env } from './env';
|
|
2
|
+
|
|
3
|
+
/** Projet poad de l'application, lu dans les variables d'environnement (env.json) */
|
|
4
|
+
export interface PoadConfig {
|
|
5
|
+
/** URL du projet poad (gateway) : POAD_URL */
|
|
6
|
+
url: string;
|
|
7
|
+
/** Clé anon du projet : publique, elle ne donne que les droits du rôle anon (POAD_ANON_KEY) */
|
|
8
|
+
anonKey: string;
|
|
9
|
+
/** Interface web des e-mails du projet local, Mailpit (POAD_MAIL_URL) */
|
|
10
|
+
mail?: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function loadConfig(): PoadConfig | null {
|
|
14
|
+
const url = env('POAD_URL');
|
|
15
|
+
const anonKey = env('POAD_ANON_KEY');
|
|
16
|
+
return url && anonKey ? { url, anonKey, mail: env('POAD_MAIL_URL') ?? null } : null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variables d'environnement, chargées AU DÉMARRAGE depuis /env.json (avant le
|
|
3
|
+
* bootstrap, voir main.ts) : la même image se déploie partout, seules les
|
|
4
|
+
* variables du conteneur changent.
|
|
5
|
+
*
|
|
6
|
+
* - en local : `bun start` écrit public/env.json (scripts/env.mjs) ;
|
|
7
|
+
* - dans l'image Docker : docker/40-env-json.sh l'écrit au démarrage.
|
|
8
|
+
*
|
|
9
|
+
* Seules y figurent les variables PUBLIC_* et POAD_URL, POAD_ANON_KEY, POAD_MAIL_URL.
|
|
10
|
+
*/
|
|
11
|
+
let values: Record<string, string> = {};
|
|
12
|
+
|
|
13
|
+
export async function loadEnv(): Promise<void> {
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetch('/env.json', { cache: 'no-store' });
|
|
16
|
+
if (res.ok) values = (await res.json()) as Record<string, string>;
|
|
17
|
+
} catch {
|
|
18
|
+
/* pas de fichier : l'application affichera la page d'aide (/setup) */
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Valeur d'une variable : env('PUBLIC_API_URL'), env('POAD_URL') */
|
|
23
|
+
export function env(name: string): string | undefined;
|
|
24
|
+
export function env(name: string, fallback: string): string;
|
|
25
|
+
export function env(name: string, fallback?: string): string | undefined {
|
|
26
|
+
return values[name] ?? fallback;
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { inject } from '@angular/core';
|
|
2
|
+
import { Router, type CanActivateFn } from '@angular/router';
|
|
3
|
+
import { AuthService, HOME_SIGNED_IN } from './auth.service';
|
|
4
|
+
|
|
5
|
+
/** Exige public/poad.json ; sinon, page d'aide à la configuration */
|
|
6
|
+
export const configured: CanActivateFn = () => (inject(AuthService).config() ? true : inject(Router).parseUrl('/setup'));
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Exige une session. Avec mfa (défaut), exige aussi la vérification en deux
|
|
10
|
+
* étapes quand l'utilisateur a un facteur ; avec roles, l'un de ces rôles
|
|
11
|
+
* (app_metadata.roles, attribués côté serveur).
|
|
12
|
+
*/
|
|
13
|
+
export const signedIn =
|
|
14
|
+
(options: { mfa?: boolean; roles?: string[] } = {}): CanActivateFn =>
|
|
15
|
+
(_route, state) => {
|
|
16
|
+
const auth = inject(AuthService);
|
|
17
|
+
const router = inject(Router);
|
|
18
|
+
if (!auth.config()) return router.parseUrl('/setup');
|
|
19
|
+
if (!auth.session()) return router.createUrlTree(['/login'], { queryParams: { next: state.url } });
|
|
20
|
+
if (options.mfa !== false && auth.needsMfa()) return router.parseUrl('/mfa');
|
|
21
|
+
if (options.roles?.length) {
|
|
22
|
+
const roles = (auth.user()?.app_metadata?.['roles'] as string[] | undefined) ?? [];
|
|
23
|
+
if (!options.roles.some((r) => roles.includes(r))) return router.parseUrl(HOME_SIGNED_IN);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Pages de connexion : inutiles une fois connecté */
|
|
29
|
+
export const signedOut: CanActivateFn = () => {
|
|
30
|
+
const auth = inject(AuthService);
|
|
31
|
+
if (!auth.config()) return inject(Router).parseUrl('/setup');
|
|
32
|
+
return auth.session() ? inject(Router).parseUrl(auth.needsMfa() ? '/mfa' : HOME_SIGNED_IN) : true;
|
|
33
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type AuthError } from '@poadio/client-js';
|
|
2
|
+
|
|
3
|
+
const formatDelay = (s: number): string => (s < 90 ? `${s} s` : `${Math.ceil(s / 60)} min`);
|
|
4
|
+
|
|
5
|
+
const WEAK: Record<string, string> = {
|
|
6
|
+
length: 'Mot de passe trop court (8 caractères au moins)',
|
|
7
|
+
characters: 'Le mot de passe doit mélanger les types de caractères demandés',
|
|
8
|
+
pwned: 'Ce mot de passe figure dans des fuites de données connues : choisissez-en un autre',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const MESSAGES: Record<string, string> = {
|
|
12
|
+
captcha_failed: 'Vérification anti-robot refusée',
|
|
13
|
+
invalid_credentials: 'Adresse ou mot de passe incorrect',
|
|
14
|
+
email_not_confirmed: 'Adresse pas encore confirmée',
|
|
15
|
+
otp_expired: 'Code invalide ou expiré',
|
|
16
|
+
weak_password: 'Mot de passe trop faible',
|
|
17
|
+
user_already_exists: 'Un compte existe déjà avec cette adresse',
|
|
18
|
+
email_exists: 'Un compte existe déjà avec cette adresse',
|
|
19
|
+
signup_disabled: 'Les inscriptions sont fermées',
|
|
20
|
+
over_request_rate_limit: 'Trop de tentatives',
|
|
21
|
+
over_email_send_rate_limit: 'Attendez avant de redemander un e-mail',
|
|
22
|
+
smtp_not_configured: 'Le projet ne peut pas envoyer d’e-mails (aucun serveur SMTP)',
|
|
23
|
+
mfa_verification_failed: 'Code incorrect',
|
|
24
|
+
mfa_verification_rejected: 'Trop de codes faux, facteur verrouillé 15 min',
|
|
25
|
+
same_password: 'Le nouveau mot de passe doit être différent',
|
|
26
|
+
session_missing: 'Pas de session',
|
|
27
|
+
network_error: 'Projet poad injoignable',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Message lisible pour une erreur du service auth */
|
|
31
|
+
export function authMessage(error: AuthError): { title: string; detail?: string } {
|
|
32
|
+
if (error.code === 'weak_password') {
|
|
33
|
+
const reason = error.reasons?.[0];
|
|
34
|
+
return { title: (reason && WEAK[reason]) || MESSAGES['weak_password'], detail: error.message };
|
|
35
|
+
}
|
|
36
|
+
const wait = error.retryAfter ? `Réessayez dans ${formatDelay(error.retryAfter)}.` : undefined;
|
|
37
|
+
return { title: MESSAGES[error.code] ?? error.message, detail: wait };
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { createClient, type AuthClient, type PoadClient, type StorageClient } from '@poadio/client-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Le client du projet poad (@poadio/client-js), à injecter dans les pages :
|
|
6
|
+
*
|
|
7
|
+
* private readonly poad = inject(Poad);
|
|
8
|
+
* this.poad.auth.updateUser({ data: { name } });
|
|
9
|
+
* this.poad.storage.from('documents').upload(path, file);
|
|
10
|
+
* this.poad.fetch('/functions/v1/hello');
|
|
11
|
+
*
|
|
12
|
+
* Il est créé au démarrage par AuthService.init(), à partir de env.json
|
|
13
|
+
* (POAD_URL, POAD_ANON_KEY). L'état de la session, en signaux, reste dans
|
|
14
|
+
* AuthService.
|
|
15
|
+
*/
|
|
16
|
+
@Injectable({ providedIn: 'root' })
|
|
17
|
+
export class Poad {
|
|
18
|
+
private instance: PoadClient | null = null;
|
|
19
|
+
|
|
20
|
+
/** Crée le client (une fois, au démarrage) */
|
|
21
|
+
connect(url: string, anonKey: string): PoadClient {
|
|
22
|
+
this.instance = createClient(url, anonKey);
|
|
23
|
+
return this.instance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get configured(): boolean {
|
|
27
|
+
return this.instance !== null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get client(): PoadClient {
|
|
31
|
+
if (!this.instance) throw new Error('poad non configuré (POAD_URL, POAD_ANON_KEY)');
|
|
32
|
+
return this.instance;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get auth(): AuthClient {
|
|
36
|
+
return this.client.auth;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get storage(): StorageClient {
|
|
40
|
+
return this.client.storage;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fetch(input: string | URL, init?: RequestInit): Promise<Response> {
|
|
44
|
+
return this.client.fetch(input, init);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Nom affiché des fournisseurs connus ; les autres gardent leur nom technique */
|
|
2
|
+
const LABELS: Record<string, string> = {
|
|
3
|
+
google: 'Google',
|
|
4
|
+
github: 'GitHub',
|
|
5
|
+
gitlab: 'GitLab',
|
|
6
|
+
keycloak: 'Keycloak',
|
|
7
|
+
keycloack: 'Keycloak',
|
|
8
|
+
apple: 'Apple',
|
|
9
|
+
azure: 'Microsoft',
|
|
10
|
+
slack: 'Slack',
|
|
11
|
+
linkedin: 'LinkedIn',
|
|
12
|
+
twitch: 'Twitch',
|
|
13
|
+
discord: 'Discord',
|
|
14
|
+
facebook: 'Facebook',
|
|
15
|
+
spotify: 'Spotify',
|
|
16
|
+
bitbucket: 'Bitbucket',
|
|
17
|
+
notion: 'Notion',
|
|
18
|
+
zoom: 'Zoom',
|
|
19
|
+
workos: 'WorkOS',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Logos fournis dans public/providers (les autres gardent l'icône générique) */
|
|
23
|
+
const LOGOS: Record<string, string> = {
|
|
24
|
+
google: 'providers/google.svg',
|
|
25
|
+
keycloak: 'providers/keycloak.svg',
|
|
26
|
+
keycloack: 'providers/keycloak.svg',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const providerLogo = (name: string): string | null => LOGOS[name] ?? null;
|
|
30
|
+
|
|
31
|
+
export const providerLabel = (name: string): string =>
|
|
32
|
+
LABELS[name] ?? name.replace(/[-_]+/g, ' ').replace(/^\w/, (c) => c.toUpperCase());
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Injectable, signal } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
const KEY = 'app.theme';
|
|
4
|
+
|
|
5
|
+
/** Thème clair / sombre : classe .theme-dark sur <html>, choix gardé dans le navigateur */
|
|
6
|
+
@Injectable({ providedIn: 'root' })
|
|
7
|
+
export class ThemeService {
|
|
8
|
+
readonly dark = signal(this.initial());
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this.apply();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
toggle(): void {
|
|
15
|
+
this.dark.update((d) => !d);
|
|
16
|
+
this.apply();
|
|
17
|
+
try {
|
|
18
|
+
localStorage.setItem(KEY, this.dark() ? 'dark' : 'light');
|
|
19
|
+
} catch {
|
|
20
|
+
/* stockage indisponible */
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private apply(): void {
|
|
25
|
+
document.documentElement.classList.toggle('theme-dark', this.dark());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private initial(): boolean {
|
|
29
|
+
try {
|
|
30
|
+
const saved = localStorage.getItem(KEY);
|
|
31
|
+
if (saved) return saved === 'dark';
|
|
32
|
+
} catch {
|
|
33
|
+
/* stockage indisponible */
|
|
34
|
+
}
|
|
35
|
+
return window.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
|
|
36
|
+
}
|
|
37
|
+
}
|