@tech4good/angular-schematics 21.5.0 → 21.6.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/CHANGELOG.md +16 -0
- package/package.json +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +2 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +2 -1
- package/src/entity/index.js +57 -0
- package/src/entity/index.js.map +1 -1
- package/src/entity/schema.json +4 -0
- package/src/ng-add/files/.gitignore.template +2 -0
- package/src/ng-add/files/docs-infra/authentication-architecture.md.template +270 -0
- package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +16 -10
- package/src/ng-add/files/firebase.json.template +6 -0
- package/src/ng-add/files/firestore.indexes.json.template +23 -0
- package/src/ng-add/files/firestore.rules.spec.ts.template +84 -15
- package/src/ng-add/files/firestore.rules.template +29 -17
- package/src/ng-add/files/functions/.gitignore.template +3 -0
- package/src/ng-add/files/functions/package.json.template +12 -0
- package/src/ng-add/files/functions/src/index.ts.template +44 -0
- package/src/ng-add/files/functions/tsconfig.json.template +13 -0
- package/src/ng-add/files/package.json.template +5 -3
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +3 -1
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +6 -8
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -2
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +6 -0
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +9 -4
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +6 -1
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +38 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +3 -2
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +7 -2
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +11 -5
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +34 -17
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +147 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +104 -17
- package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +116 -0
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +367 -70
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +4 -1
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +52 -66
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +127 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +216 -147
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +2 -4
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.html.template +4 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.scss.template +1 -0
- package/src/ng-add/files/src/app/first-time/auth-action/auth-action.component.ts.template +38 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +5 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +12 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +93 -48
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +5 -1
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.html.template +18 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.scss.template +2 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +40 -0
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +76 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +7 -2
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +19 -7
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +51 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +29 -5
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +12 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +31 -10
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +6 -19
- package/src/ng-add/files/src/app/first-time/login/login.component.html.template +58 -6
- package/src/ng-add/files/src/app/first-time/login/login.component.scss.template +151 -22
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +18 -38
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +59 -31
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.html.template +12 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.scss.template +39 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +68 -0
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.ts.template +20 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.html.template +24 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.scss.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +65 -0
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/guest-deletion-dialog.component.ts.template +51 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.html.template +50 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.scss.template +137 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +57 -0
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.ts.template +59 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.html.template +133 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.scss.template +207 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +74 -0
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.ts.template +130 -0
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +0 -5
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.html.template +15 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.scss.template +79 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +59 -0
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.ts.template +44 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +45 -15
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.scss.template +103 -19
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +73 -9
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.ts.template +46 -18
- package/src/ng-add/files/src/environments/environment.prod.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.test.ts.template +1 -0
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/index_spec.d.ts +1 -0
- package/src/ng-add/index_spec.js +108 -0
- package/src/ng-add/index_spec.js.map +1 -0
- package/tsconfig.json +2 -2
|
@@ -53,14 +53,12 @@ export const USER_DB: User[] = [
|
|
|
53
53
|
{
|
|
54
54
|
__id: '1',
|
|
55
55
|
name: 'User A',
|
|
56
|
-
photoURL: 'http://loremflickr.com/100/100?lock=1',
|
|
57
56
|
isAdmin: true,
|
|
58
|
-
consented:
|
|
59
|
-
accessState: AccessState.
|
|
57
|
+
consented: true,
|
|
58
|
+
accessState: AccessState.DONE,
|
|
60
59
|
_createdAt: Timestamp.now(),
|
|
61
60
|
_updatedAt: Timestamp.now(),
|
|
62
61
|
_deleted: false,
|
|
63
62
|
},
|
|
64
63
|
...MOCK_USER_LIST,
|
|
65
64
|
];
|
|
66
|
-
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.auth-action { max-width: 430px; margin: 80px auto; text-align: center; display: grid; justify-items: center; gap: 16px; }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
|
2
|
+
import { ActivatedRoute, Router } from '@angular/router';
|
|
3
|
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Endpoint view for handling Firebase Auth email action redirects (`/auth/action`).
|
|
7
|
+
*
|
|
8
|
+
* Configured in Firebase Console as the default action handler. Receives URL query parameters
|
|
9
|
+
* (such as `mode=signIn` and action codes) and forwards valid email link sign-in flows to `/email-link`.
|
|
10
|
+
*/
|
|
11
|
+
@Component({
|
|
12
|
+
selector: 'app-auth-action',
|
|
13
|
+
templateUrl: './auth-action.component.html',
|
|
14
|
+
styleUrl: './auth-action.component.scss',
|
|
15
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
16
|
+
imports: [MatProgressSpinnerModule],
|
|
17
|
+
})
|
|
18
|
+
export class AuthActionComponent implements OnInit {
|
|
19
|
+
private readonly route = inject(ActivatedRoute);
|
|
20
|
+
private readonly router = inject(Router);
|
|
21
|
+
|
|
22
|
+
/** Status message displayed to the user while processing the email action callback. */
|
|
23
|
+
readonly message = signal('Completing your secure email action…');
|
|
24
|
+
|
|
25
|
+
async ngOnInit(): Promise<void> {
|
|
26
|
+
const params = this.route.snapshot.queryParams;
|
|
27
|
+
const mode = params['mode'];
|
|
28
|
+
try {
|
|
29
|
+
if (mode === 'signIn') {
|
|
30
|
+
await this.router.navigate(['/email-link'], { queryParams: params });
|
|
31
|
+
} else {
|
|
32
|
+
this.message.set('This email action is not valid or has expired.');
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
this.message.set('This email action is not valid or has expired. Request a new email and try again.');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -4,6 +4,7 @@ import { map } from 'rxjs/operators';
|
|
|
4
4
|
import { AuthService } from '../../core/auth/auth.service';
|
|
5
5
|
import { User, AccessState } from '../../core/store/user/user.model';
|
|
6
6
|
import { hasAdminOverride } from '../../core/auth/guards/admin-override';
|
|
7
|
+
import { environment } from 'src/environments/environment';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Single guard logic for the consent page that checks two conditions:
|
|
@@ -20,11 +21,14 @@ export function handleAccess(
|
|
|
20
21
|
router: Router,
|
|
21
22
|
route: ActivatedRouteSnapshot,
|
|
22
23
|
state: RouterStateSnapshot,
|
|
24
|
+
hasWaitlist: boolean = environment.hasWaitlist,
|
|
23
25
|
): boolean {
|
|
24
26
|
if (hasAdminOverride(user, state.url)) return true;
|
|
25
27
|
|
|
26
28
|
// Check 1: Has the user cleared the waitlist?
|
|
27
|
-
const waitingStates =
|
|
29
|
+
const waitingStates = hasWaitlist ?
|
|
30
|
+
[AccessState.SUBMIT_INTEREST, AccessState.WAITING] :
|
|
31
|
+
[AccessState.SUBMIT_INTEREST];
|
|
28
32
|
if (user && waitingStates.includes(user.accessState)) {
|
|
29
33
|
router.navigate(['/early-access'], { queryParams: route.queryParams });
|
|
30
34
|
return false;
|
package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template
CHANGED
|
@@ -57,6 +57,7 @@ async function setup(providers: Provider[] = [], seededUsers: any[] = []) {
|
|
|
57
57
|
routerMock,
|
|
58
58
|
snackBarMock,
|
|
59
59
|
batchWriteMock: view.fixture.debugElement.injector.get(BATCH_WRITE_SERVICE) as any,
|
|
60
|
+
authStore: view.fixture.debugElement.injector.get(AuthStore),
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -74,6 +75,14 @@ describe('EarlyAccessComponent', () => {
|
|
|
74
75
|
expect(screen.getByRole('button', { name: /Submit/i })).toBeDisabled();
|
|
75
76
|
});
|
|
76
77
|
|
|
78
|
+
it('should safely clear the page when the authenticated user is removed during account deletion', async () => {
|
|
79
|
+
const { authStore, fixture } = await setup();
|
|
80
|
+
|
|
81
|
+
await authStore.deleteAnonymousAccount();
|
|
82
|
+
expect(() => fixture.detectChanges()).not.toThrow();
|
|
83
|
+
expect(screen.queryByText(/Please help us understand/i)).not.toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
|
|
77
86
|
it('should enforce minLength validators on survey inputs', async () => {
|
|
78
87
|
const { user } = await setup();
|
|
79
88
|
|
|
@@ -100,7 +109,7 @@ describe('EarlyAccessComponent', () => {
|
|
|
100
109
|
});
|
|
101
110
|
|
|
102
111
|
it('should perform batch write and update accessState and user context on submit', async () => {
|
|
103
|
-
const { user, batchWriteMock, snackBarMock } = await setup();
|
|
112
|
+
const { user, batchWriteMock, snackBarMock, routerMock } = await setup();
|
|
104
113
|
|
|
105
114
|
const writeSpy = jest.spyOn(batchWriteMock, 'batchWrite');
|
|
106
115
|
|
|
@@ -133,11 +142,13 @@ describe('EarlyAccessComponent', () => {
|
|
|
133
142
|
expect(updateCall).toBeDefined();
|
|
134
143
|
const changes = updateCall[1];
|
|
135
144
|
expect(changes.joinedWaitlistAt).toBeInstanceOf(Timestamp);
|
|
145
|
+
expect(changes.accessState).toBe(AccessState.CONSENT);
|
|
136
146
|
|
|
137
147
|
// Verify success notification shown with Undo action
|
|
138
148
|
await waitFor(() => {
|
|
139
149
|
expect(snackBarMock.open).toHaveBeenCalledWith('Submitted interest form!', 'Undo', expect.any(Object));
|
|
140
150
|
});
|
|
151
|
+
expect(routerMock.navigate).toHaveBeenCalledWith(['/consent'], { queryParams: undefined });
|
|
141
152
|
|
|
142
153
|
writeSpy.mockRestore();
|
|
143
154
|
});
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
OnInit,
|
|
4
|
+
OnDestroy,
|
|
5
|
+
ChangeDetectionStrategy,
|
|
6
|
+
computed,
|
|
7
|
+
Inject,
|
|
8
|
+
input,
|
|
9
|
+
output,
|
|
10
|
+
inject,
|
|
11
|
+
signal,
|
|
12
|
+
WritableSignal,
|
|
13
|
+
Signal,
|
|
14
|
+
Injector,
|
|
15
|
+
effect,
|
|
16
|
+
} from '@angular/core';
|
|
2
17
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
3
18
|
import { Observable } from 'rxjs';
|
|
4
19
|
import { filter, mergeMap } from 'rxjs/operators';
|
|
@@ -17,18 +32,14 @@ import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
17
32
|
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
18
33
|
import { UserStore } from 'src/app/core/store/user/user.store';
|
|
19
34
|
import { UserContextStore } from 'src/app/core/store/user-context/user-context.store';
|
|
35
|
+
import { environment } from 'src/environments/environment';
|
|
20
36
|
|
|
21
37
|
@Component({
|
|
22
38
|
selector: 'app-early-access',
|
|
23
39
|
templateUrl: './early-access.component.html',
|
|
24
40
|
styleUrl: './early-access.component.scss',
|
|
25
41
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
26
|
-
imports: [
|
|
27
|
-
NavbarComponent,
|
|
28
|
-
AsyncPipe,
|
|
29
|
-
SurveyFormComponent,
|
|
30
|
-
WaitlistViewComponent,
|
|
31
|
-
],
|
|
42
|
+
imports: [NavbarComponent, AsyncPipe, SurveyFormComponent, WaitlistViewComponent],
|
|
32
43
|
})
|
|
33
44
|
export class EarlyAccessComponent implements OnInit {
|
|
34
45
|
readonly authStore = inject(AuthStore);
|
|
@@ -54,13 +65,18 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
54
65
|
outreachLeadName = 'OUTREACH_LEAD_NAME [FirstName]';
|
|
55
66
|
outreachLeadEmail = 'OUTREACH_LEAD_EMAIL [email@ucsc.edu]';
|
|
56
67
|
|
|
57
|
-
|
|
58
68
|
// --------------- COMPUTED DATA -----------------------
|
|
59
69
|
|
|
60
70
|
/** Waitlist data from app-state, user, and user-context. */
|
|
61
|
-
waitlistData: Signal<WaitlistData> = computed(() => {
|
|
62
|
-
const
|
|
63
|
-
|
|
71
|
+
waitlistData: Signal<WaitlistData | null> = computed(() => {
|
|
72
|
+
const currentUser = this.currentUser();
|
|
73
|
+
if (!currentUser) return null;
|
|
74
|
+
|
|
75
|
+
const userContext = this.userContextStore.selectFirst(
|
|
76
|
+
[['__userId', '==', currentUser.__id]],
|
|
77
|
+
{},
|
|
78
|
+
);
|
|
79
|
+
return { currentUser, userContext };
|
|
64
80
|
});
|
|
65
81
|
|
|
66
82
|
/** Waiting position number. */
|
|
@@ -71,10 +87,13 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
71
87
|
const compareDate = user.joinedWaitlistAt || user._createdAt;
|
|
72
88
|
if (!compareDate) return '';
|
|
73
89
|
|
|
74
|
-
const posNum = await this.userStore.count(
|
|
75
|
-
[
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
const posNum = await this.userStore.count(
|
|
91
|
+
[
|
|
92
|
+
['joinedWaitlistAt', '<=', compareDate],
|
|
93
|
+
['accessState', '==', AccessState.WAITING],
|
|
94
|
+
],
|
|
95
|
+
{},
|
|
96
|
+
);
|
|
78
97
|
return this.nth(posNum === 0 ? 1 : posNum);
|
|
79
98
|
} catch (e) {
|
|
80
99
|
console.error('Error calculating position:', e);
|
|
@@ -88,9 +107,7 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
88
107
|
filter((user: User) => !!user),
|
|
89
108
|
mergeMap(async (user) => {
|
|
90
109
|
try {
|
|
91
|
-
const total = await this.userStore.count([
|
|
92
|
-
['accessState', '==', AccessState.WAITING],
|
|
93
|
-
], {});
|
|
110
|
+
const total = await this.userStore.count([['accessState', '==', AccessState.WAITING]], {});
|
|
94
111
|
return `${total}`;
|
|
95
112
|
} catch (e) {
|
|
96
113
|
console.error('Error calculating total:', e);
|
|
@@ -102,10 +119,14 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
102
119
|
/** Function for adding the appropriate suffix. */
|
|
103
120
|
nth(n: number): string {
|
|
104
121
|
switch (n % 10) {
|
|
105
|
-
case 1:
|
|
106
|
-
|
|
107
|
-
case
|
|
108
|
-
|
|
122
|
+
case 1:
|
|
123
|
+
return `${n}st`;
|
|
124
|
+
case 2:
|
|
125
|
+
return `${n}nd`;
|
|
126
|
+
case 3:
|
|
127
|
+
return `${n}rd`;
|
|
128
|
+
default:
|
|
129
|
+
return `${n}th`;
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
|
|
@@ -113,34 +134,58 @@ export class EarlyAccessComponent implements OnInit {
|
|
|
113
134
|
|
|
114
135
|
/** Submit background and interests. */
|
|
115
136
|
async submitInterest(formData: SurveyData) {
|
|
137
|
+
const waitlistData = this.waitlistData();
|
|
138
|
+
if (!waitlistData) return;
|
|
139
|
+
|
|
116
140
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
const hasWaitlist = environment.hasWaitlist;
|
|
142
|
+
const targetState = hasWaitlist ? AccessState.WAITING : AccessState.CONSENT;
|
|
143
|
+
|
|
144
|
+
await this.batch.batchWrite(
|
|
145
|
+
async (batchConfig) => {
|
|
146
|
+
await this.userStore.update(
|
|
147
|
+
waitlistData.currentUser.__id,
|
|
148
|
+
{
|
|
149
|
+
accessState: targetState,
|
|
150
|
+
joinedWaitlistAt: Timestamp.now(),
|
|
151
|
+
},
|
|
152
|
+
{ batchConfig },
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
if (waitlistData.userContext) {
|
|
156
|
+
this.userContextStore.update(
|
|
157
|
+
waitlistData.userContext.__id,
|
|
158
|
+
{
|
|
159
|
+
questionOne: formData.questionOne ?? '',
|
|
160
|
+
questionTwo: formData.questionTwo ?? '',
|
|
161
|
+
},
|
|
162
|
+
{ batchConfig },
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
this.userContextStore.add(
|
|
166
|
+
{
|
|
167
|
+
__userId: waitlistData.currentUser.__id,
|
|
168
|
+
questionOne: formData.questionOne ?? '',
|
|
169
|
+
questionTwo: formData.questionTwo ?? '',
|
|
170
|
+
},
|
|
171
|
+
{ batchConfig },
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
loading: this.loading,
|
|
177
|
+
snackBarConfig: {
|
|
178
|
+
successMessage: 'Submitted interest form!',
|
|
179
|
+
failureMessage: 'Failed to submit response',
|
|
180
|
+
undoOnAction: true,
|
|
181
|
+
config: { duration: 3000 },
|
|
182
|
+
},
|
|
142
183
|
},
|
|
143
|
-
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
if (!hasWaitlist) {
|
|
187
|
+
await this.router.navigate(['/consent'], { queryParams: this.route.snapshot.queryParams });
|
|
188
|
+
}
|
|
144
189
|
} catch (e) {
|
|
145
190
|
console.error(e);
|
|
146
191
|
}
|
|
@@ -4,6 +4,7 @@ import { map } from 'rxjs/operators';
|
|
|
4
4
|
import { AuthService } from '../../core/auth/auth.service';
|
|
5
5
|
import { User, AccessState } from '../../core/store/user/user.model';
|
|
6
6
|
import { hasAdminOverride } from '../../core/auth/guards/admin-override';
|
|
7
|
+
import { environment } from 'src/environments/environment';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Ensures the user is currently on the waitlist. Users who have already
|
|
@@ -17,10 +18,13 @@ export function handleAccess(
|
|
|
17
18
|
router: Router,
|
|
18
19
|
route: ActivatedRouteSnapshot,
|
|
19
20
|
state: RouterStateSnapshot,
|
|
21
|
+
hasWaitlist: boolean = environment.hasWaitlist,
|
|
20
22
|
): boolean {
|
|
21
23
|
if (hasAdminOverride(user, state.url)) return true;
|
|
22
24
|
|
|
23
|
-
const waitingStates =
|
|
25
|
+
const waitingStates = hasWaitlist ?
|
|
26
|
+
[AccessState.SUBMIT_INTEREST, AccessState.WAITING] :
|
|
27
|
+
[AccessState.SUBMIT_INTEREST];
|
|
24
28
|
if (user && !waitingStates.includes(user.accessState)) {
|
|
25
29
|
// Fully completed onboarding → go straight to home
|
|
26
30
|
if (user.consented && user.accessState === AccessState.DONE) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<main class="email-link">
|
|
2
|
+
@if (isSubmitting()) {
|
|
3
|
+
<h1>Signing you in…</h1>
|
|
4
|
+
<p>Completing your secure email link.</p>
|
|
5
|
+
} @else {
|
|
6
|
+
<h1>Confirm your email</h1>
|
|
7
|
+
<p>Enter the email address where you received this link.</p>
|
|
8
|
+
<form (submit)="complete(); $event.preventDefault()">
|
|
9
|
+
<mat-form-field appearance="outline">
|
|
10
|
+
<mat-label>Email</mat-label>
|
|
11
|
+
<input matInput type="email" [formField]="form.email" autocomplete="email" />
|
|
12
|
+
@if (form.email().touched() && form.email().invalid()) { <mat-error>Enter a valid email address.</mat-error> }
|
|
13
|
+
</mat-form-field>
|
|
14
|
+
<button mat-flat-button color="primary" type="submit">Continue</button>
|
|
15
|
+
</form>
|
|
16
|
+
}
|
|
17
|
+
@if (message()) { <p role="status">{{ message() }}</p> }
|
|
18
|
+
</main>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Router } from '@angular/router';
|
|
2
|
+
import { render, screen, waitFor } from '@testing-library/angular';
|
|
3
|
+
import { EmailLinkComponent } from './email-link.component';
|
|
4
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
5
|
+
|
|
6
|
+
describe('EmailLinkComponent', () => {
|
|
7
|
+
it('completes automatically when the request email is stored in this browser', async () => {
|
|
8
|
+
const completeEmailSignInLink = jest.fn().mockResolvedValue({});
|
|
9
|
+
const getStoredEmailForEmailLink = jest.fn().mockReturnValue('learner@example.com');
|
|
10
|
+
const router = { navigate: jest.fn().mockResolvedValue(true) };
|
|
11
|
+
await render(EmailLinkComponent, {
|
|
12
|
+
providers: [
|
|
13
|
+
{
|
|
14
|
+
provide: AuthStore,
|
|
15
|
+
useValue: {
|
|
16
|
+
getStoredEmailForEmailLink,
|
|
17
|
+
completeEmailSignInLink,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{ provide: Router, useValue: router },
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await waitFor(() => expect(completeEmailSignInLink).toHaveBeenCalledWith(window.location.href, 'learner@example.com'));
|
|
25
|
+
expect(getStoredEmailForEmailLink).toHaveBeenCalledTimes(1);
|
|
26
|
+
expect(router.navigate).toHaveBeenCalledWith(['/home']);
|
|
27
|
+
expect(screen.queryByLabelText('Email')).not.toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('asks for the email when the link is opened without same-browser state', async () => {
|
|
31
|
+
await render(EmailLinkComponent, {
|
|
32
|
+
providers: [
|
|
33
|
+
{ provide: AuthStore, useValue: { getStoredEmailForEmailLink: () => null } },
|
|
34
|
+
{ provide: Router, useValue: { navigate: jest.fn() } },
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(screen.getByLabelText('Email')).toBeVisible();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
|
|
2
|
+
import { form, FormField, required, email, submit } from '@angular/forms/signals';
|
|
3
|
+
import { Router } from '@angular/router';
|
|
4
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
5
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
6
|
+
import { MatInputModule } from '@angular/material/input';
|
|
7
|
+
import { AuthStore } from 'src/app/core/store/auth/auth.store';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handles the completion phase of email magic-link authentication (`/email-link`).
|
|
11
|
+
*
|
|
12
|
+
* If the link was opened in the same browser session where it was requested, the target email
|
|
13
|
+
* is automatically retrieved from `EmailLinkContextService`. If opened in a different browser/device
|
|
14
|
+
* or if local storage was cleared, the component prompts the user to re-enter their email.
|
|
15
|
+
*/
|
|
16
|
+
@Component({
|
|
17
|
+
selector: 'app-email-link',
|
|
18
|
+
templateUrl: './email-link.component.html',
|
|
19
|
+
styleUrl: './email-link.component.scss',
|
|
20
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
21
|
+
imports: [FormField, MatButtonModule, MatFormFieldModule, MatInputModule],
|
|
22
|
+
})
|
|
23
|
+
export class EmailLinkComponent implements OnInit {
|
|
24
|
+
private readonly authStore = inject(AuthStore);
|
|
25
|
+
private readonly router = inject(Router);
|
|
26
|
+
private readonly storedEmail = this.authStore.getStoredEmailForEmailLink();
|
|
27
|
+
|
|
28
|
+
/** User-facing status or error message. */
|
|
29
|
+
readonly message = signal<string | null>(null);
|
|
30
|
+
|
|
31
|
+
/** Whether the email link completion request is currently processing. */
|
|
32
|
+
readonly isSubmitting = signal(Boolean(this.storedEmail));
|
|
33
|
+
|
|
34
|
+
/** Signal form model for the manual email entry fallback. */
|
|
35
|
+
readonly emailModel = signal({
|
|
36
|
+
email: this.storedEmail || '',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** Signal-based form validation schema for email input. */
|
|
40
|
+
readonly form = form(this.emailModel, (s) => {
|
|
41
|
+
required(s.email, { message: 'Email is required' });
|
|
42
|
+
email(s.email, { message: 'Enter a valid email address.' });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
async ngOnInit(): Promise<void> {
|
|
46
|
+
if (this.storedEmail) await this.completeWith(this.storedEmail);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Triggers manual completion when the user submits their email address. */
|
|
50
|
+
async complete(): Promise<void> {
|
|
51
|
+
await submit(this.form, async () => {
|
|
52
|
+
await this.completeWith(this.emailModel().email);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Verifies the email link URL and completes sign-in or account linking via AuthStore.
|
|
58
|
+
*/
|
|
59
|
+
private async completeWith(email: string): Promise<void> {
|
|
60
|
+
this.isSubmitting.set(true);
|
|
61
|
+
this.message.set(null);
|
|
62
|
+
try {
|
|
63
|
+
await this.authStore.completeEmailSignInLink(window.location.href, email);
|
|
64
|
+
await this.router.navigate(['/home']);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const code = (error as { code?: string }).code;
|
|
67
|
+
this.message.set(
|
|
68
|
+
code === 'auth/link-requires-original-session' ?
|
|
69
|
+
'Return to the browser where you started this account upgrade to save that guest progress.' :
|
|
70
|
+
'This sign-in link is invalid, expired, or for a different email. Request a new link and try again.',
|
|
71
|
+
);
|
|
72
|
+
} finally {
|
|
73
|
+
this.isSubmitting.set(false);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -18,20 +18,22 @@ import { createMockUser } from '../core/store/user/user.mock';
|
|
|
18
18
|
describe('First-Time / Onboarding Routing', () => {
|
|
19
19
|
let harness: RouterTestingHarness;
|
|
20
20
|
let router: Router;
|
|
21
|
-
let mockAuthService: { resolveUser: jest.Mock };
|
|
21
|
+
let mockAuthService: { resolveUser: jest.Mock; resolveSession: jest.Mock };
|
|
22
22
|
let mockUserSignal: any;
|
|
23
23
|
|
|
24
24
|
beforeEach(async () => {
|
|
25
25
|
mockAuthService = {
|
|
26
26
|
resolveUser: jest.fn().mockReturnValue(of(null)),
|
|
27
|
+
resolveSession: jest.fn().mockReturnValue(of(null)),
|
|
27
28
|
};
|
|
28
29
|
mockUserSignal = signal(null);
|
|
30
|
+
const mockAfUserSignal = signal(null);
|
|
29
31
|
|
|
30
32
|
await TestBed.configureTestingModule({
|
|
31
33
|
providers: [
|
|
32
34
|
provideRouter(routes),
|
|
33
35
|
{ provide: AuthService, useValue: mockAuthService },
|
|
34
|
-
{ provide: AuthStore, useValue: { user: mockUserSignal } },
|
|
36
|
+
{ provide: AuthStore, useValue: { user: mockUserSignal, afUser: mockAfUserSignal } },
|
|
35
37
|
{ provide: DATABASE_SERVICE, useClass: FirebaseMockService },
|
|
36
38
|
{ provide: BATCH_WRITE_SERVICE, useClass: BatchWriteMockService },
|
|
37
39
|
{ provide: LOG_SERVICE, useClass: LogInDevService },
|
|
@@ -46,6 +48,7 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
46
48
|
beforeEach(() => {
|
|
47
49
|
const u = createMockUser({ accessState: AccessState.SUBMIT_INTEREST, consented: false });
|
|
48
50
|
mockAuthService.resolveUser.mockReturnValue(of(u));
|
|
51
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
49
52
|
mockUserSignal.set(u);
|
|
50
53
|
});
|
|
51
54
|
|
|
@@ -72,6 +75,7 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
72
75
|
beforeEach(() => {
|
|
73
76
|
const u = createMockUser({ accessState: AccessState.CONSENT, consented: false });
|
|
74
77
|
mockAuthService.resolveUser.mockReturnValue(of(u));
|
|
78
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
75
79
|
mockUserSignal.set(u);
|
|
76
80
|
});
|
|
77
81
|
|
|
@@ -99,6 +103,7 @@ describe('First-Time / Onboarding Routing', () => {
|
|
|
99
103
|
beforeEach(() => {
|
|
100
104
|
const fullyOnboardedUser = createMockUser({ accessState: AccessState.DONE, consented: true });
|
|
101
105
|
mockAuthService.resolveUser.mockReturnValue(of(fullyOnboardedUser));
|
|
106
|
+
mockAuthService.resolveSession.mockReturnValue(of({ isAnonymous: false, emailVerified: true }));
|
|
102
107
|
mockUserSignal.set(fullyOnboardedUser);
|
|
103
108
|
});
|
|
104
109
|
|
|
@@ -4,14 +4,26 @@
|
|
|
4
4
|
<div class="hero-subtitle">
|
|
5
5
|
<app-rotating-quotes [sentences]="sentences"></app-rotating-quotes>
|
|
6
6
|
</div>
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
<div class="cta-actions">
|
|
8
|
+
<a class="cta-button" href="/login" (click)="onGetStarted($event)">Get started</a>
|
|
9
|
+
@if (showGuestLogin()) {
|
|
10
|
+
<button
|
|
11
|
+
class="try-guest"
|
|
12
|
+
type="button"
|
|
13
|
+
[disabled]="isGuestLoading()"
|
|
14
|
+
(click)="tryWithoutLoggingIn()"
|
|
15
|
+
>
|
|
16
|
+
@if (isGuestLoading()) {
|
|
17
|
+
<svg class="spinner-icon" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
18
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56"/>
|
|
19
|
+
</svg>
|
|
20
|
+
<span>Creating guest session...</span>
|
|
21
|
+
} @else {
|
|
22
|
+
<span>Try without logging in</span>
|
|
23
|
+
}
|
|
24
|
+
</button>
|
|
13
25
|
}
|
|
14
|
-
</
|
|
26
|
+
</div>
|
|
15
27
|
</div>
|
|
16
28
|
<div class="hero-visual" animate.enter="animate-fade-in-up">
|
|
17
29
|
<img src="/images/abstract.png" alt="Abstract illustration placeholder" />
|