@tech4good/angular-schematics 20.1.0 → 20.3.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/.agents/skills/publish-npm/SKILL.md +37 -0
- package/.agents/skills/publish-npm/eval.yaml +17 -0
- package/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +66 -0
- package/README.md +16 -7
- package/changelog.config.json +19 -0
- package/contributing-docs/branches-and-releases.md +57 -0
- package/contributing-docs/commit-message.md +117 -0
- package/package.json +10 -2
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +1 -0
- package/src/component/schema.json +1 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +1 -1
- package/src/entity/schema.json +1 -0
- package/src/ng-add/files/.gitignore.template +3 -0
- package/src/ng-add/files/package.json.template +3 -2
- package/src/ng-add/files/public/images/abstract.png +0 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +27 -22
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.scss.template +35 -4
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +31 -75
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.html.template +25 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.scss.template +67 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.ts.template +74 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.html.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.ts.template +36 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.html.template +11 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.ts.template +47 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.html.template +52 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.scss.template +66 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +220 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.html.template +81 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.scss.template +136 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +118 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -0
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +14 -18
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +58 -0
- package/src/ng-add/files/src/app/core/auth/guards/admin-override.ts.template +9 -0
- package/src/ng-add/files/src/app/core/auth/guards/index.ts.template +11 -0
- package/src/ng-add/files/src/app/core/auth/guards/redirect-if-authenticated.guard.ts.template +42 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +39 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +69 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth.guard.ts.template +35 -0
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +2 -17
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +1 -1
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +7 -1
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +71 -6
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +94 -53
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +5 -5
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +5 -7
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +3 -5
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +2 -5
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +4 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +54 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.animations.ts.template +6 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.html.template +70 -52
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.scss.template +73 -6
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +59 -111
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +44 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.animations.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +12 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +79 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +20 -0
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +1 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +11 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.html.template +3 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.scss.template +26 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.ts.template +52 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.html.template +21 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.scss.template +71 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.ts.template +70 -0
- package/src/ng-add/files/src/app/shared/hint-visibility/hint-visibility.directive.ts.template +131 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +2 -2
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/files/src/index.html.template +3 -2
- package/src/ng-add/files/src/styles/_variables.scss.template +1 -0
- package/src/ng-add/files/src/styles.scss.template +4 -2
- package/src/ng-add/schema.json +1 -0
- package/src/ng-add/files/src/app/core/auth/auth.guard.ts.template +0 -96
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Component, inject, computed } from '@angular/core';
|
|
2
|
+
import { Router, NavigationEnd, RouterLink } from '@angular/router';
|
|
3
|
+
import { MatIcon } from '@angular/material/icon';
|
|
4
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
5
|
+
import { filter, map } from 'rxjs/operators';
|
|
6
|
+
import { interval } from 'rxjs';
|
|
7
|
+
import { AuthStore } from '../../core/store/auth/auth.store';
|
|
8
|
+
import { environment } from '../../../environments/environment';
|
|
9
|
+
|
|
10
|
+
@Component({
|
|
11
|
+
selector: 'app-dev-status-bar',
|
|
12
|
+
standalone: true,
|
|
13
|
+
imports: [MatIcon, RouterLink],
|
|
14
|
+
templateUrl: './dev-status-bar.component.html',
|
|
15
|
+
styleUrls: ['./dev-status-bar.component.scss'],
|
|
16
|
+
})
|
|
17
|
+
export class DevStatusBarComponent {
|
|
18
|
+
private readonly authStore = inject(AuthStore);
|
|
19
|
+
private readonly router = inject(Router);
|
|
20
|
+
|
|
21
|
+
// --------------- INPUTS AND OUTPUTS ------------------
|
|
22
|
+
|
|
23
|
+
/** Current route URL, updated on every navigation. */
|
|
24
|
+
private readonly currentUrl = toSignal(
|
|
25
|
+
this.router.events.pipe(
|
|
26
|
+
filter((event): event is NavigationEnd => event instanceof NavigationEnd),
|
|
27
|
+
map((event) => event.urlAfterRedirects),
|
|
28
|
+
),
|
|
29
|
+
{ initialValue: this.router.url },
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// --------------- COMPUTED DATA -----------------------
|
|
33
|
+
|
|
34
|
+
/** Whether the admin override is active for the current route. */
|
|
35
|
+
readonly showAdminOverride = computed(() => {
|
|
36
|
+
const user = this.authStore.user();
|
|
37
|
+
const url = this.currentUrl();
|
|
38
|
+
if (!user?.isAdmin || !user.adminOverridePaths?.length) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return user.adminOverridePaths.includes(url);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
private checkHasMockData(): boolean {
|
|
45
|
+
if (!environment['mockDB']) return false;
|
|
46
|
+
return Object.keys(localStorage).some(
|
|
47
|
+
(key) => key.startsWith('mockDB_') || key === 'mockUser',
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether there is local storage data for Mock DB, polled every second. */
|
|
52
|
+
readonly showMockDbWarning = toSignal(
|
|
53
|
+
interval(1000).pipe(map(() => this.checkHasMockData())),
|
|
54
|
+
{ initialValue: this.checkHasMockData() },
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// --------------- EVENT HANDLING ----------------------
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Clears all mock data from localStorage and reloads the page to reset the application state.
|
|
61
|
+
*/
|
|
62
|
+
clearMockData() {
|
|
63
|
+
Object.keys(localStorage).forEach((key) => {
|
|
64
|
+
if (key.startsWith('mockDB_') || key === 'mockUser') {
|
|
65
|
+
localStorage.removeItem(key);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
window.location.reload();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Directive, DestroyRef, inject, input, signal, OnInit } from '@angular/core';
|
|
2
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
3
|
+
import { AbstractControl } from '@angular/forms';
|
|
4
|
+
import { debounceTime } from 'rxjs/operators';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Directive that manages when to show a form-field hint based on:
|
|
8
|
+
* - **Inactivity timer**: After the user stops typing for a configurable duration
|
|
9
|
+
* (default: 3 seconds), the hint appears — but only when the input is under
|
|
10
|
+
* a character threshold (default: 50). This avoids nagging users who are
|
|
11
|
+
* actively composing long answers while also making sure to notify those who
|
|
12
|
+
* haven't reached the limit.
|
|
13
|
+
* - **Blur fallback**: When the user clicks/tabs away from the field, the hint
|
|
14
|
+
* appears immediately if the field has been interacted with (dirty).
|
|
15
|
+
* - **Cross-field gating**: The timer-based hint only fires when a specified
|
|
16
|
+
* sibling control is valid, preventing premature hints when the other field
|
|
17
|
+
* hasn't been filled yet.
|
|
18
|
+
*
|
|
19
|
+
* ## Usage
|
|
20
|
+
* ```html
|
|
21
|
+
* <textarea matInput
|
|
22
|
+
* appHintVisibility
|
|
23
|
+
* [hintControl]="surveyForm.get('menteeCountAndFrequency')!"
|
|
24
|
+
* [hintSiblingControl]="surveyForm.get('interactionTopicsAndHurdle')!"
|
|
25
|
+
* #menteeHint="hintVisibility">
|
|
26
|
+
* </textarea>
|
|
27
|
+
*
|
|
28
|
+
* @if (menteeHint.showHint()) {
|
|
29
|
+
* <mat-hint>Your hint text here</mat-hint>
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
@Directive({
|
|
34
|
+
selector: '[appHintVisibility]',
|
|
35
|
+
exportAs: 'hintVisibility',
|
|
36
|
+
standalone: true,
|
|
37
|
+
host: {
|
|
38
|
+
'(blur)': 'onBlur()',
|
|
39
|
+
'(focus)': 'onFocus()',
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
export class HintVisibilityDirective implements OnInit {
|
|
43
|
+
private destroyRef = inject(DestroyRef);
|
|
44
|
+
|
|
45
|
+
// --------------- INPUTS --------------------------------
|
|
46
|
+
|
|
47
|
+
/** The form control attached to this input. */
|
|
48
|
+
hintControl = input.required<AbstractControl>();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The sibling form control whose validity gates the timer-based hint.
|
|
52
|
+
* The debounced hint will only appear when this control is valid.
|
|
53
|
+
*/
|
|
54
|
+
hintSiblingControl = input<AbstractControl | null>(null);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Minimum character count below which the inactivity timer will trigger.
|
|
58
|
+
* Once the user types this many characters, hints only show on blur.
|
|
59
|
+
*/
|
|
60
|
+
hintCharThreshold = input<number>(50);
|
|
61
|
+
|
|
62
|
+
/** Duration of typing inactivity (in ms) before showing the hint. */
|
|
63
|
+
hintDebounceMs = input<number>(3000);
|
|
64
|
+
|
|
65
|
+
// --------------- STATE ---------------------------------
|
|
66
|
+
|
|
67
|
+
/** Whether the hint should currently be visible. Read this in the template. */
|
|
68
|
+
showHint = signal(false);
|
|
69
|
+
|
|
70
|
+
// --------------- LIFECYCLE -----------------------------
|
|
71
|
+
|
|
72
|
+
ngOnInit() {
|
|
73
|
+
const control = this.hintControl();
|
|
74
|
+
|
|
75
|
+
control.valueChanges.pipe(
|
|
76
|
+
// Wait for the configured period of typing inactivity before the
|
|
77
|
+
// *initial* hint trigger. Once visible, the hint stays visible so the
|
|
78
|
+
// user can track their character count in real-time as they type.
|
|
79
|
+
debounceTime(this.hintDebounceMs()),
|
|
80
|
+
|
|
81
|
+
takeUntilDestroyed(this.destroyRef),
|
|
82
|
+
).subscribe((val: string | null) => {
|
|
83
|
+
const length = (val || '').length;
|
|
84
|
+
const sibling = this.hintSiblingControl();
|
|
85
|
+
|
|
86
|
+
// If the field has been cleared, hide the hint — there's nothing
|
|
87
|
+
// useful to show and this prevents a stale hint from persisting
|
|
88
|
+
// after the user types and deletes.
|
|
89
|
+
if (length === 0) {
|
|
90
|
+
this.showHint.set(false);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Show the hint on a delay only when ALL of the following are true:
|
|
95
|
+
// 1. The user has actually typed something (dirty).
|
|
96
|
+
// 2. They haven't yet reached the character threshold.
|
|
97
|
+
// 3. The sibling control (if provided) is already valid.
|
|
98
|
+
// If the threshold is met, the hint will only appear on blur instead.
|
|
99
|
+
const siblingValid = sibling ? sibling.valid : true;
|
|
100
|
+
if (control.dirty && length < this.hintCharThreshold() && siblingValid) {
|
|
101
|
+
this.showHint.set(true);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// --------------- HOST EVENT HANDLERS -------------------
|
|
107
|
+
|
|
108
|
+
/** Show hint immediately when the user leaves the field, if they've typed. */
|
|
109
|
+
onBlur() {
|
|
110
|
+
const control = this.hintControl();
|
|
111
|
+
// Only show on blur if there's actual content — if the user typed
|
|
112
|
+
// and then deleted everything, we don't want to latch showHint to
|
|
113
|
+
// true since there's nothing useful to hint about.
|
|
114
|
+
if (control.dirty && control.value) {
|
|
115
|
+
this.showHint.set(true);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* When the user returns to this field, reset the sibling's form state
|
|
121
|
+
* if it hasn't been filled yet. This prevents the sibling from appearing
|
|
122
|
+
* "dirty" prematurely when the user backtracks to an earlier question.
|
|
123
|
+
*/
|
|
124
|
+
onFocus() {
|
|
125
|
+
const sibling = this.hintSiblingControl();
|
|
126
|
+
if (sibling && !sibling.value) {
|
|
127
|
+
sibling.markAsUntouched();
|
|
128
|
+
sibling.markAsPristine();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<!--<img class="logo" src="images/logo.svg">-->
|
|
3
3
|
@if (currentUser()) {
|
|
4
4
|
<div class="user-setting-section">
|
|
5
|
-
<img class="profile-pic" [src]=
|
|
5
|
+
<img class="profile-pic" [src]="currentUser().photoURL" referrerpolicy="no-referrer" [matMenuTriggerFor]="menu" #menuTrigger/>
|
|
6
6
|
<mat-menu #menu="matMenu">
|
|
7
7
|
<div class="logout" (click)="logout()">
|
|
8
8
|
<span>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
|
-
import { BehaviorSubject, Observable, interval, Subject,
|
|
3
|
-
import { startWith, multicast, distinctUntilChanged,
|
|
2
|
+
import { BehaviorSubject, Observable, interval, Subject, ConnectableObservable } from 'rxjs';
|
|
3
|
+
import { startWith, multicast, distinctUntilChanged, map, filter, mergeMap, skip } from 'rxjs/operators';
|
|
4
4
|
|
|
5
5
|
@Injectable({
|
|
6
6
|
providedIn: 'root',
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
<base href="/" />
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
8
8
|
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
|
9
|
-
<link rel="preconnect" href="https://fonts.
|
|
10
|
-
<link href="https://fonts.
|
|
9
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
10
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
11
|
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Source+Serif+4:opsz,wght@8..60,400;8..60,600&display=swap" rel="stylesheet">
|
|
11
12
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
|
|
12
13
|
</head>
|
|
13
14
|
<body>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$bg-primary: #FDFBF7;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/* You can add global styles to this file, and also import other style files */
|
|
2
2
|
|
|
3
|
+
@use 'styles/variables' as *;
|
|
4
|
+
|
|
3
5
|
html, body, app-root {
|
|
4
6
|
height: 100%;
|
|
5
7
|
box-sizing: border-box;
|
|
6
8
|
padding: 0;
|
|
7
9
|
margin: 0;
|
|
8
|
-
font-family:
|
|
10
|
+
font-family: 'Inter', "Helvetica Neue", sans-serif;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
*, *:before, *:after {
|
|
@@ -13,5 +15,5 @@ html, body, app-root {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
body {
|
|
16
|
-
background-color:
|
|
18
|
+
background-color: $bg-primary;
|
|
17
19
|
}
|
package/src/ng-add/schema.json
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"proceed": {
|
|
20
20
|
"type": "boolean",
|
|
21
|
+
"default": true,
|
|
21
22
|
"x-prompt": "This schematic is only designed for generating initial files on a FRESH repo created from ng new. If you use this outside of that context, YOU WILL OVERWRITE parts of your existing code. Are you sure you want to proceed?"
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Inject, inject, Injectable } from '@angular/core';
|
|
2
|
-
import { ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
|
|
3
|
-
import { User, AccessState } from '../store/user/user.model';
|
|
4
|
-
import { AuthStore } from '../store/auth/auth.store';
|
|
5
|
-
import { filter, switchMap, take } from 'rxjs/operators';
|
|
6
|
-
import { of, Observable } from 'rxjs';
|
|
7
|
-
import { toObservable } from '@angular/core/rxjs-interop';
|
|
8
|
-
import { DATABASE_SERVICE, DatabaseService } from '../firebase/database.service';
|
|
9
|
-
|
|
10
|
-
@Injectable({
|
|
11
|
-
providedIn: 'root',
|
|
12
|
-
})
|
|
13
|
-
export class AuthGuard {
|
|
14
|
-
readonly authStore = inject(AuthStore);
|
|
15
|
-
user$: Observable<User>;
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
private router: Router,
|
|
19
|
-
@Inject(DATABASE_SERVICE) private db: DatabaseService,
|
|
20
|
-
) {
|
|
21
|
-
// This is only used when we have a signed in user, so we want to filter
|
|
22
|
-
// out the values before the user has been loaded into the store
|
|
23
|
-
this.user$ = toObservable(this.authStore.user).pipe(
|
|
24
|
-
filter((user) => !!user),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
|
29
|
-
return this.db.afUser().pipe(
|
|
30
|
-
switchMap((afUser) => afUser ? this.user$.pipe(take(1)) : of(null)),
|
|
31
|
-
switchMap((dbUser) => {
|
|
32
|
-
// The overall approach is that we have a sequence of things we need to check (signed in, consent, waiting, walkthrough).
|
|
33
|
-
// - For each, we want to make sure people not past that stage can't see past it,
|
|
34
|
-
// - We also want to make sure people already past that stage get auto-moved past that page,
|
|
35
|
-
// - We preserve queryParams in case we want to support things like referral links in the future,
|
|
36
|
-
// - Admin users are also handled (so that only admin users can go to admin pages, including pages they would
|
|
37
|
-
// typically get rerouted from)
|
|
38
|
-
|
|
39
|
-
// First handle all not logged in cases. If not logged in, users can only go to landing
|
|
40
|
-
if (!dbUser) {
|
|
41
|
-
if (state.url === '/' || state.url === '/landing' || state.url === '/login') {
|
|
42
|
-
return of(true);
|
|
43
|
-
} else {
|
|
44
|
-
this.router.navigate(['/'], { queryParams: next.queryParams });
|
|
45
|
-
return of(false);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// AFTER THIS POINT, THE USER MUST BE LOGGED IN (i.e. dbUser exists)
|
|
50
|
-
|
|
51
|
-
// If logged in and trying to access landing, redirect to the homepage
|
|
52
|
-
if (state.url === '/' || state.url === '/landing' || state.url === '/login') {
|
|
53
|
-
this.router.navigate(['/home'], { queryParams: next.queryParams });
|
|
54
|
-
return of(false);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Make sure non-admin users can't visit admin pages and admin users can visit any page
|
|
58
|
-
// Note: this also means there isn't the same auto-redirection/authguard behavior for admins
|
|
59
|
-
if (!dbUser.isAdmin && state.url.startsWith('/admin')) {
|
|
60
|
-
this.router.navigate(['/home'], { queryParams: next.queryParams });
|
|
61
|
-
return of(false);
|
|
62
|
-
} else if (dbUser.isAdmin) {
|
|
63
|
-
return of(true);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Then handle whether users have consented. If not, go to consent, otherwise skip past consent.
|
|
67
|
-
if ((!dbUser.consented || dbUser.accessState === AccessState.CONSENT) && state.url !== '/consent') {
|
|
68
|
-
this.router.navigate(['/consent'], { queryParams: next.queryParams });
|
|
69
|
-
return of(false);
|
|
70
|
-
} else if ((!dbUser.consented || dbUser.accessState === AccessState.CONSENT) && state.url === '/consent') {
|
|
71
|
-
return of(true);
|
|
72
|
-
} else if (dbUser.consented && dbUser.accessState !== AccessState.CONSENT && state.url === '/consent') {
|
|
73
|
-
this.router.navigate(['/early-access'], { queryParams: next.queryParams });
|
|
74
|
-
return of(false);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Then handle whether users are past waitlist. If not, go to waiting, otherwise skip past waiting.
|
|
78
|
-
const waitingStates = [AccessState.SUBMIT_INTEREST, AccessState.WAITING];
|
|
79
|
-
if (waitingStates.includes(dbUser.accessState) && state.url !== '/early-access') {
|
|
80
|
-
this.router.navigate(['/early-access'], { queryParams: next.queryParams });
|
|
81
|
-
return of(false);
|
|
82
|
-
} else if (waitingStates.includes(dbUser.accessState) && state.url === '/early-access') {
|
|
83
|
-
return of(true);
|
|
84
|
-
} else if (!waitingStates.includes(dbUser.accessState) && state.url === '/early-access') {
|
|
85
|
-
this.router.navigate(['/home'], { queryParams: next.queryParams });
|
|
86
|
-
return of(false);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// PLACEHOLDER: Add similar logic to waitlist states if there is an app-specific walkthrough process
|
|
90
|
-
|
|
91
|
-
// For anything else, return true
|
|
92
|
-
return of(true);
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|