@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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [21.6.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.5.0...v21.6.0) (2026-07-28)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **entity:** support foreign key fields and automated composite firestore index generation ([99ae303](https://github.com/tech4good-lab/angular-schematics/commit/99ae303cd6eee6fae24fda7c994a178e0aa5be11))
|
|
6
|
+
* **ng-add:** add account profile, guest banner, and login UI components ([174d9a5](https://github.com/tech4good-lab/angular-schematics/commit/174d9a5f6d92a14e359e44193f98289bb30d9dac))
|
|
7
|
+
* **ng-add:** add cloud functions infrastructure and security rules ([9c65a61](https://github.com/tech4good-lab/angular-schematics/commit/9c65a6119880243c5f624ddb312ed61e287dbe47))
|
|
8
|
+
* **ng-add:** enhance auth services, stores, and guards ([3396eee](https://github.com/tech4good-lab/angular-schematics/commit/3396eee629a85865fd66f9965825aca4e564956a))
|
|
9
|
+
* **ng-add:** update auth token initialization and test environments ([9206c6b](https://github.com/tech4good-lab/angular-schematics/commit/9206c6b5e591d3aa77de82a37225094b724f1955))
|
|
10
|
+
* **ng-add:** update default firestore indexes and security rule state transitions ([28e851f](https://github.com/tech4good-lab/angular-schematics/commit/28e851fd5cdf9d9c441ceeebcd11080c87f69261))
|
|
11
|
+
* **ng-add:** update landing, hero, and early access component layouts ([78b8918](https://github.com/tech4good-lab/angular-schematics/commit/78b891855a5a0340384e339fb2a7e56bb12f6fd3))
|
|
12
|
+
* **shared:** align navbar component layout and avatar fallback ([9f80c5f](https://github.com/tech4good-lab/angular-schematics/commit/9f80c5f296ff5c2d0ba3245d5656031ead804683))
|
|
13
|
+
|
|
14
|
+
### Build System
|
|
15
|
+
|
|
16
|
+
* **ng-add:** bump template dependency for release ([5e0b098](https://github.com/tech4good-lab/angular-schematics/commit/5e0b0981629d0adddffc5b7d66e955d1cd9ae86e))
|
|
1
17
|
## [21.5.0](https://github.com/tech4good-lab/angular-schematics/compare/v21.4.0...v21.5.0) (2026-07-22)
|
|
2
18
|
|
|
3
19
|
### Features
|
package/package.json
CHANGED
|
@@ -14,7 +14,8 @@ export const <%= classify(name) %>MockDB = signalStore(
|
|
|
14
14
|
*/
|
|
15
15
|
export function createMock<%= classify(name) %>(overrides?: Partial<<%= classify(name) %>>): <%= classify(name) %> {
|
|
16
16
|
return {
|
|
17
|
-
__id: '<%= dasherize(name) %>-default'
|
|
17
|
+
__id: '<%= dasherize(name) %>-default',<% if (parsedForeignKeys && parsedForeignKeys.length > 0) { parsedForeignKeys.forEach(function(fk) { %>
|
|
18
|
+
__<%= fk %>: '<%= fk %>-default',<% }); } %>
|
|
18
19
|
_createdAt: Timestamp.now(),
|
|
19
20
|
_updatedAt: Timestamp.now(),
|
|
20
21
|
_deleted: false,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Timestamp } from '@angular/fire/firestore';
|
|
2
2
|
|
|
3
3
|
export interface <%= classify(name) %> {
|
|
4
|
-
__id: string
|
|
4
|
+
__id: string;<% if (parsedForeignKeys && parsedForeignKeys.length > 0) { parsedForeignKeys.forEach(function(fk) { %>
|
|
5
|
+
__<%= fk %>: string;<% }); } %>
|
|
5
6
|
_createdAt?: Timestamp;
|
|
6
7
|
_updatedAt?: Timestamp;
|
|
7
8
|
_deleted?: boolean;
|
package/src/entity/index.js
CHANGED
|
@@ -88,6 +88,47 @@ function addInserts(options) {
|
|
|
88
88
|
return host;
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
function addFirestoreIndex(options) {
|
|
92
|
+
return (host, context) => {
|
|
93
|
+
const parsedForeignKeys = options.parsedForeignKeys || [];
|
|
94
|
+
if (parsedForeignKeys.length === 0) {
|
|
95
|
+
return host;
|
|
96
|
+
}
|
|
97
|
+
const indexPath = '/firestore.indexes.json';
|
|
98
|
+
if (!host.exists(indexPath)) {
|
|
99
|
+
context.logger.warn('firestore.indexes.json not found — skipping index generation.');
|
|
100
|
+
return host;
|
|
101
|
+
}
|
|
102
|
+
const camelizedName = core_1.strings.camelize(options.name);
|
|
103
|
+
const collectionGroup = camelizedName + 's';
|
|
104
|
+
// Build the composite index fields: foreign keys + _deleted + _updatedAt + __name__
|
|
105
|
+
const fields = [
|
|
106
|
+
...parsedForeignKeys.map((fk) => ({
|
|
107
|
+
fieldPath: `__${fk}`,
|
|
108
|
+
order: 'ASCENDING',
|
|
109
|
+
})),
|
|
110
|
+
{ fieldPath: '_deleted', order: 'ASCENDING' },
|
|
111
|
+
{ fieldPath: '_updatedAt', order: 'ASCENDING' },
|
|
112
|
+
{ fieldPath: '__name__', order: 'ASCENDING' },
|
|
113
|
+
];
|
|
114
|
+
const newIndex = {
|
|
115
|
+
collectionGroup,
|
|
116
|
+
queryScope: 'COLLECTION',
|
|
117
|
+
fields,
|
|
118
|
+
density: 'SPARSE_ALL',
|
|
119
|
+
};
|
|
120
|
+
const indexContent = host.read(indexPath);
|
|
121
|
+
if (!indexContent) {
|
|
122
|
+
context.logger.warn('Could not read firestore.indexes.json — skipping index generation.');
|
|
123
|
+
return host;
|
|
124
|
+
}
|
|
125
|
+
const indexJson = JSON.parse(indexContent.toString());
|
|
126
|
+
indexJson.indexes.push(newIndex);
|
|
127
|
+
host.overwrite(indexPath, JSON.stringify(indexJson, null, 2) + '\n');
|
|
128
|
+
context.logger.info(`Added composite Firestore index for ${collectionGroup} with foreign keys: ${parsedForeignKeys.map(fk => '__' + fk).join(', ')}`);
|
|
129
|
+
return host;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
91
132
|
function entity(options) {
|
|
92
133
|
return async (tree, context) => {
|
|
93
134
|
const workspace = await (0, workspace_1.getWorkspace)(tree);
|
|
@@ -123,6 +164,11 @@ function entity(options) {
|
|
|
123
164
|
const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
|
|
124
165
|
options.name = parsedPath.name;
|
|
125
166
|
options.path = parsedPath.path;
|
|
167
|
+
// Parse foreign keys from comma-separated string
|
|
168
|
+
const parsedForeignKeys = options.foreignKeys
|
|
169
|
+
? options.foreignKeys.split(',').map((k) => k.trim()).filter((k) => k.length > 0)
|
|
170
|
+
: [];
|
|
171
|
+
options.parsedForeignKeys = parsedForeignKeys;
|
|
126
172
|
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
127
173
|
(0, schematics_1.applyTemplates)({
|
|
128
174
|
...core_1.strings,
|
|
@@ -130,8 +176,19 @@ function entity(options) {
|
|
|
130
176
|
}),
|
|
131
177
|
(0, schematics_1.move)(parsedPath.path),
|
|
132
178
|
]);
|
|
179
|
+
// Post-generation reminder about foreign keys and indexes
|
|
180
|
+
if (parsedForeignKeys.length > 0) {
|
|
181
|
+
context.logger.info(`\n📋 REMINDER: Don't forget to deploy the updated Firestore indexes:\n` +
|
|
182
|
+
` firebase deploy --only firestore:indexes\n`);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
context.logger.info(`\n📋 REMINDER: If your entity has foreign key fields (e.g., __userId, __collectionId),\n` +
|
|
186
|
+
` re-generate with --foreign-keys to create the required composite Firestore indexes:\n` +
|
|
187
|
+
` ng generate @tech4good/angular-schematics:entity ${options.name} --foreign-keys=userId,collectionId\n`);
|
|
188
|
+
}
|
|
133
189
|
return (0, schematics_1.chain)([
|
|
134
190
|
addInserts(options),
|
|
191
|
+
addFirestoreIndex(options),
|
|
135
192
|
(0, schematics_1.mergeWith)(templateSource)
|
|
136
193
|
]);
|
|
137
194
|
};
|
package/src/entity/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AA4KA,wBA4EC;AAxPD,2DAIoC;AAEpC,+DAA0E;AAC1E,yEAA4E;AAC5E,uEAAmE;AACnE,qEAAuF;AACvF,+CAA+C;AAE/C,iEAAuF;AAEvF,SAAS,UAAU,CAAC,OAAY;IAC9B,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAE/C,MAAM,cAAc,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,aAAa,GAAG,cAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,MAAM,cAAc,GAAG,cAAO,C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AO,CAAC;YACnB,iBAAiB,CAAC,OAAO,CAAC;YAC1B,IAAA,sBAAS,EAAC,cAAc,CAAC;SAC1B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/src/entity/schema.json
CHANGED
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"index": 0
|
|
34
34
|
},
|
|
35
35
|
"x-prompt": "What name would you like to use for the entity?"
|
|
36
|
+
},
|
|
37
|
+
"foreignKeys": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "Comma-separated list of foreign key names (without __ prefix). E.g., 'userId,collectionId'. These will be added to the model interface as __fieldName: string fields, and composite Firestore indexes will be generated for efficient querying."
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"required": [
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Authentication architecture
|
|
2
|
+
|
|
3
|
+
This document is the implementation reference for application authentication. It describes the production system as implemented in the Angular application, Firebase configuration, Firestore rules, and Cloud Functions.
|
|
4
|
+
|
|
5
|
+
## Goals and boundaries
|
|
6
|
+
|
|
7
|
+
The application supports three sign-in paths:
|
|
8
|
+
|
|
9
|
+
| Path | Firebase provider | Intended use |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| Google | `google.com` | One-click sign-in or upgrading a guest account with a Google identity. |
|
|
12
|
+
| Email magic link | Firebase Email/Password provider with email-link credentials | Passwordless sign-in and upgrading a guest account while preserving progress. |
|
|
13
|
+
| Guest | `anonymous` | Immediate, low-friction access; progress remains recoverable only by linking Google or an email address. |
|
|
14
|
+
|
|
15
|
+
The application does not provide password creation, password sign-in, or password reset screens. Firebase’s Email/Password provider remains enabled only because Firebase implements email-link sign-in through that provider.
|
|
16
|
+
|
|
17
|
+
Authentication establishes identity. The Firestore `users/{uid}` document establishes application state such as onboarding progress, consent, and administrator status. Both are required for access to private application routes.
|
|
18
|
+
|
|
19
|
+
## Firebase Console configuration
|
|
20
|
+
|
|
21
|
+
Configure every Firebase project independently (development and production):
|
|
22
|
+
|
|
23
|
+
1. Enable **Google**, **Email link (passwordless sign-in)**, and **Anonymous** under **Authentication → Sign-in method**. Keep the Email/Password provider enabled as required by Firebase for email links.
|
|
24
|
+
2. Keep **Email enumeration protection** enabled.
|
|
25
|
+
3. Use Firebase’s one-account-per-email behavior so Google and email-link credentials for the same email resolve to one Firebase user instead of separate accounts.
|
|
26
|
+
4. Add each deployed host to **Authentication → Settings → Authorized domains**. At minimum this includes project hosts such as `<project-dev>.web.app` and `<project>.web.app`; add custom hosts as they are introduced.
|
|
27
|
+
5. Leave the Firebase email template’s action URL at its project default (`https://<project>.firebaseapp.com/__/auth/action`). The app action then returns the browser to `/auth/action` on the originating application host.
|
|
28
|
+
6. Deploy the `deleteAnonymousAccount` callable Cloud Function before enabling guest deletion.
|
|
29
|
+
|
|
30
|
+
The application intentionally does not call `fetchSignInMethodsForEmail`. Provider discovery would weaken enumeration protection and cannot safely resolve account-collision recovery.
|
|
31
|
+
|
|
32
|
+
## Main application components
|
|
33
|
+
|
|
34
|
+
| Responsibility | Implementation |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| Firebase SDK operations | `src/app/core/firebase/firebase.service.ts` |
|
|
37
|
+
| Small Firebase abstraction used by stores and tests | `src/app/core/firebase/database.service.ts` |
|
|
38
|
+
| Auth and application-user state | `src/app/core/store/auth/auth.store.ts` |
|
|
39
|
+
| Guard-facing auth resolution | `src/app/core/auth/auth.service.ts` |
|
|
40
|
+
| Email-link same-browser context | `src/app/core/firebase/email-link-context.service.ts` |
|
|
41
|
+
| Public entry and guest start | `src/app/first-time/landing/` |
|
|
42
|
+
| Email action and completion views | `src/app/first-time/auth-action/`, `src/app/first-time/email-link/` |
|
|
43
|
+
| Account linking/deletion UI | `src/app/main/account-profile/` |
|
|
44
|
+
| Guest deletion backend | `functions/src/index.ts` |
|
|
45
|
+
|
|
46
|
+
`AppComponent` calls `AuthStore.loadAuth()` once during application startup. That long-lived subscription remains active for the lifetime of the app so the UI can react to sign-in, sign-out, session revocation, and authentication changes from another tab.
|
|
47
|
+
|
|
48
|
+
```mermaid
|
|
49
|
+
flowchart TD
|
|
50
|
+
subgraph UI ["UI & Routing Layer"]
|
|
51
|
+
Views["Views & Components<br/>(Landing, Action, Security)"]
|
|
52
|
+
Guards["Route Guards<br/>(requireAuth, requireAuthAndConsent, etc.)"]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
subgraph State ["State Management Layer"]
|
|
56
|
+
AuthStore["AuthStore<br/>(afUser session & profile loading)"]
|
|
57
|
+
UserStore["UserStore<br/>(User profile & access state)"]
|
|
58
|
+
AuthService["AuthService<br/>(Guard authentication resolution)"]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
subgraph Infra ["Services & Infrastructure"]
|
|
62
|
+
FirebaseService["FirebaseService<br/>(Firebase Auth SDK operations)"]
|
|
63
|
+
ContextService["EmailLinkContextService<br/>(Cookie & LocalStorage context)"]
|
|
64
|
+
Firestore[("Firestore DB<br/>users/{uid} & userPrivates/{uid}")]
|
|
65
|
+
Functions["Cloud Functions<br/>(deleteAnonymousAccount)"]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
Guards -->|"resolves auth"| AuthService
|
|
69
|
+
AuthService -->|"queries state"| AuthStore
|
|
70
|
+
Views -->|"triggers sign-in / linking"| AuthStore
|
|
71
|
+
AuthStore -->|"derives user"| UserStore
|
|
72
|
+
AuthStore -->|"calls SDK methods"| FirebaseService
|
|
73
|
+
AuthStore -->|"provisions profile"| Firestore
|
|
74
|
+
FirebaseService -->|"stores link context"| ContextService
|
|
75
|
+
Views -->|"invokes backend deletion"| Functions
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Session model and local state
|
|
79
|
+
|
|
80
|
+
`FirebaseService.afUser()` exposes Firebase Auth changes as an `AuthSession` containing:
|
|
81
|
+
|
|
82
|
+
- Firebase UID, email, display name, photo URL, anonymous state, and email-verification state;
|
|
83
|
+
- provider IDs (for example `google.com` or `password`);
|
|
84
|
+
- `emailLinkEnabled`, derived from Firebase provider metadata rather than Firestore.
|
|
85
|
+
|
|
86
|
+
`AuthStore` maintains the Firebase session in `afUser` and derives `user` by looking up the matching entity in `UserStore`. A Firebase session can therefore exist briefly before the application profile has loaded; guards use `AuthService.resolveUser()` to handle that distinction.
|
|
87
|
+
|
|
88
|
+
On an authenticated session, `provisionAndLoadUser()`:
|
|
89
|
+
|
|
90
|
+
1. Calls `ensureUserProfile()` to create missing `users/{uid}` and `userPrivates/{uid}` records, or update available Google profile fields.
|
|
91
|
+
2. Loads the application user into `UserStore`.
|
|
92
|
+
3. Starts a real-time stream for that user record.
|
|
93
|
+
|
|
94
|
+
Fresh sign-in methods provision directly after Firebase reports successful sign-in. The background `loadAuth()` subscription observes the same Firebase event, but skips its own provisioning while `isLoadingLogin` is true. This is important: Firestore can observe Firebase’s auth event before its credentials provider has installed the new token. A duplicate read in that narrow window can fail with `permission-denied` / “Missing or insufficient permissions.”
|
|
95
|
+
|
|
96
|
+
The background subscription is deliberately not unsubscribed on logout. Instead, logout tears down Firestore streams and resets stores while retaining the app-wide Firebase auth observer for the next sign-in or an external auth change.
|
|
97
|
+
|
|
98
|
+
Because RxJS cannot cancel an already-running provisioning Promise, logout and account deletion first block new refresh provisioning and wait for any active refresh provisioning to settle. Only then do they tear down Firestore streams and sign out. This ordering prevents a delayed `userStore.stream()` call from recreating a listener under signed-out credentials.
|
|
99
|
+
|
|
100
|
+
## Account creation and profile data
|
|
101
|
+
|
|
102
|
+
`ensureUserProfile()` creates a new application profile when the Firebase UID has no matching document:
|
|
103
|
+
|
|
104
|
+
- `users/{uid}` contains the application identity and onboarding state. New accounts begin at `SUBMIT_INTEREST` and are not administrators or consented.
|
|
105
|
+
- `userPrivates/{uid}` contains the email when Firebase provides one, plus email-link capability metadata.
|
|
106
|
+
|
|
107
|
+
Google provides display name and photo URL. Those values are copied to an existing guest profile when available.
|
|
108
|
+
|
|
109
|
+
Email magic links provide a verified email address but do not provide a display name or profile image. The application therefore preserves the existing guest profile, displays the email address on the account page, and uses the initials avatar fallback until the user sets a display name. It does not manufacture a name or avatar from an email address.
|
|
110
|
+
|
|
111
|
+
## Google flow
|
|
112
|
+
|
|
113
|
+
`AuthStore.signInWithGoogle()` calls `FirebaseService.signInWithGoogle()`, which uses `signInWithPopup` and a `GoogleAuthProvider`. The resulting session is provisioned and recorded in `AuthStore`.
|
|
114
|
+
|
|
115
|
+
`AuthStore.linkGoogle()` uses `linkWithPopup` on the current Firebase user rather than creating a second application identity. It refreshes the Firebase ID token, reprovisions the existing UID, and updates the local session. If Firebase reports `auth/credential-already-in-use`, the account page explains that the Google identity belongs to another application profile.
|
|
116
|
+
|
|
117
|
+
## Email magic-link flows
|
|
118
|
+
|
|
119
|
+
```mermaid
|
|
120
|
+
sequenceDiagram
|
|
121
|
+
autonumber
|
|
122
|
+
actor User
|
|
123
|
+
participant App as Application UI
|
|
124
|
+
participant Context as EmailLinkContextService
|
|
125
|
+
participant FB as Firebase Auth SDK
|
|
126
|
+
participant Mail as User Email Inbox
|
|
127
|
+
participant Store as AuthStore / UserStore
|
|
128
|
+
|
|
129
|
+
User->>App: Request Magic Link
|
|
130
|
+
App->>Context: Store flow context (email, flow type, current UID)
|
|
131
|
+
App->>FB: sendSignInLinkToEmail(email, actionUrl)
|
|
132
|
+
FB->>Mail: Send email with magic link
|
|
133
|
+
Mail->>User: Click magic link
|
|
134
|
+
User->>FB: Open Firebase action URL
|
|
135
|
+
FB->>App: Redirect to /auth/action?mode=signIn -> /email-link
|
|
136
|
+
App->>Context: Retrieve stored context (same-browser verification)
|
|
137
|
+
App->>FB: completeEmailSignInLink() / linkWithCredential()
|
|
138
|
+
FB-->>App: Return authenticated credentials
|
|
139
|
+
App->>Store: provisionAndLoadUser()
|
|
140
|
+
Store-->>App: Load/create profile & establish active session
|
|
141
|
+
App->>User: Route to main application (/home)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Sending
|
|
145
|
+
|
|
146
|
+
`FirebaseService.sendEmailLink()` calls `sendSignInLinkToEmail` with `handleCodeInApp: true` and an action URL based on the active browser origin:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
https://<current-host>/auth/action?flow=<flow>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Before sending, `EmailLinkContextService` stores three values in both local storage (when available) and a 30-minute, `SameSite=Lax` cookie:
|
|
153
|
+
|
|
154
|
+
- requested email address;
|
|
155
|
+
- requested flow (`sign-in`, `guest-upgrade`, or `link-email`);
|
|
156
|
+
- current UID for flows that must retain the existing account.
|
|
157
|
+
|
|
158
|
+
The context makes the normal same-browser flow automatic and prevents a link intended to upgrade one guest account from being used to attach credentials to a different session. If storage is unavailable, the cookie provides the fallback.
|
|
159
|
+
|
|
160
|
+
The account page replaces its guest “Send Magic Link” button with “Magic link sent” after a successful send. A send failure leaves the button available for retry.
|
|
161
|
+
|
|
162
|
+
### Callback and completion
|
|
163
|
+
|
|
164
|
+
Firebase opens its hosted action page, which redirects to the app’s `/auth/action` route. `AuthActionComponent` accepts only `mode=signIn` and forwards the request to `/email-link`. `EmailLinkComponent` completes automatically if the email is available from same-browser context; otherwise it asks the person to enter the email again.
|
|
165
|
+
|
|
166
|
+
`FirebaseService.completeEmailSignInLink()` verifies the URL with `isSignInWithEmailLink` and selects a flow:
|
|
167
|
+
|
|
168
|
+
| Flow | Completion action |
|
|
169
|
+
| --- | --- |
|
|
170
|
+
| `sign-in` | `signInWithEmailLink`, creating or restoring an email-linked Firebase session. |
|
|
171
|
+
| `guest-upgrade` | Requires the original same-browser UID, then calls `linkWithCredential` so guest progress stays on that UID. |
|
|
172
|
+
| `link-email` | Requires the original same-browser UID, then calls `linkWithCredential` to add passwordless email sign-in to an existing account. |
|
|
173
|
+
|
|
174
|
+
After completion, the Firebase token is refreshed, the short-lived email-link context is cleared, and `AuthStore` provisions/refreshes the application profile. The callback view routes to `/home`; route guards then send users to any incomplete early-access or consent step.
|
|
175
|
+
|
|
176
|
+
If the callback is opened on a different device or browser for an upgrade/linking flow, the app does not guess which account should receive the credential. It displays the `auth/link-requires-original-session` guidance instead.
|
|
177
|
+
|
|
178
|
+
## Guest flow and account deletion
|
|
179
|
+
|
|
180
|
+
Choosing guest access calls `AuthStore.loginAnonymously()`, which creates an anonymous Firebase user, provisions the matching application profile, and then navigates through normal route guards.
|
|
181
|
+
|
|
182
|
+
Guests can preserve progress by linking Google or an email magic link. Deleting a guest account is intentionally destructive and requires confirmation.
|
|
183
|
+
|
|
184
|
+
The `deleteAnonymousAccount` callable function:
|
|
185
|
+
|
|
186
|
+
1. Requires an authenticated request whose `sign_in_provider` is `anonymous`.
|
|
187
|
+
2. Deletes guest-owned `userContexts` documents in batches. Extend `QUERY_COLLECTIONS` when the application adds other user-owned collections.
|
|
188
|
+
3. Deletes the UID-keyed `users` and `userPrivates` documents.
|
|
189
|
+
4. Deletes the Firebase Auth user.
|
|
190
|
+
|
|
191
|
+
After the callable succeeds, `AuthStore.deleteAnonymousAccount()` explicitly calls local Firebase `signOut`, patches local auth state to `null`, and routes to `/landing`. The explicit local sign-out matters: deleting a Firebase Auth user on the server does not necessarily clear the browser’s in-memory Firebase session before the landing guard runs. Without it, the guard could wait indefinitely for an application profile that the callable had already deleted.
|
|
192
|
+
|
|
193
|
+
```mermaid
|
|
194
|
+
sequenceDiagram
|
|
195
|
+
autonumber
|
|
196
|
+
actor Guest as Guest User
|
|
197
|
+
participant App as Application UI / AuthStore
|
|
198
|
+
participant CF as Cloud Function (deleteAnonymousAccount)
|
|
199
|
+
participant FS as Firestore DB
|
|
200
|
+
participant FB as Firebase Auth
|
|
201
|
+
|
|
202
|
+
Guest->>App: Request Guest Account Deletion
|
|
203
|
+
App->>CF: Call deleteAnonymousAccount()
|
|
204
|
+
CF->>FS: Delete user-owned data (userContexts by default)
|
|
205
|
+
CF->>FS: Delete users and userPrivates docs
|
|
206
|
+
CF->>FB: Delete anonymous Firebase Auth user
|
|
207
|
+
CF-->>App: Callable returns success
|
|
208
|
+
App->>FS: resetAllStores() (Teardown Firestore listeners)
|
|
209
|
+
App->>FB: Local signOut() & patch auth state to null
|
|
210
|
+
App->>Guest: Route to /landing
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Logout and listener teardown
|
|
214
|
+
|
|
215
|
+
Before any logout or guest deletion, `AuthStore.resetAllStores()`:
|
|
216
|
+
|
|
217
|
+
1. Tears down cached Firestore streams.
|
|
218
|
+
2. Resets `UserStore` and `UserContextStore`.
|
|
219
|
+
|
|
220
|
+
Tearing down streams before the token is invalidated avoids post-logout Firestore permission errors from active listeners. It also means views can briefly observe no current application user during teardown; components that derive data from the user must treat that state as valid. For example, the early-access `waitlistData` computed signal returns `null` instead of dereferencing a missing user.
|
|
221
|
+
|
|
222
|
+
The Firebase auth observer remains subscribed after logout. It is necessary for future sign-ins, cross-tab changes, and session invalidation. Direct sign-in methods use `isLoadingLogin` to ensure that this observer mirrors the new session without racing the credential-ready provisioning operation.
|
|
223
|
+
|
|
224
|
+
## Routing and authorization
|
|
225
|
+
|
|
226
|
+
Routes in `src/app/app.routes.ts` use four layers of guard behavior:
|
|
227
|
+
|
|
228
|
+
| Guard | Purpose |
|
|
229
|
+
| --- | --- |
|
|
230
|
+
| `redirectIfAuthenticated` | Keeps authenticated users off public landing/login routes; redirects them to home. |
|
|
231
|
+
| `requireAuth` | Requires a resolved application user; otherwise redirects to landing. |
|
|
232
|
+
| `earlyAccessGuard` | Keeps users in the interest/waitlist stage until their access state advances. |
|
|
233
|
+
| `requireAuthAndConsent` | Requires authentication, completion of early access, and consent before home/onboarding routes. |
|
|
234
|
+
|
|
235
|
+
`AuthService.resolveUser()` first observes Firebase Auth. If there is no Firebase session, it immediately resolves `null`; if there is a session, it returns the synchronous store user when already available or waits for the first loaded application user. This avoids guards making decisions from an incomplete Firestore load while preserving immediate redirects for logged-out users.
|
|
236
|
+
|
|
237
|
+
## Firestore authorization relationship
|
|
238
|
+
|
|
239
|
+
Firestore rules are in `firestore.rules`. The main principle is that authentication alone is not enough for every action:
|
|
240
|
+
|
|
241
|
+
- Anonymous users, Google users, and verified-email users are permitted where `isVerifiedOrAnonymous()` applies.
|
|
242
|
+
- Users can create and update their own user and private records, subject to application-state restrictions; they cannot grant themselves administrator access or bypass protected onboarding transitions.
|
|
243
|
+
- User-owned `userContexts` documents are restricted to their owning UID, with administrator exceptions.
|
|
244
|
+
- Applications must add equivalent owner checks for every additional user-owned collection they introduce.
|
|
245
|
+
|
|
246
|
+
The callable guest-deletion function uses the Admin SDK and therefore performs controlled server-side deletion rather than relying on the client to clean up every collection.
|
|
247
|
+
|
|
248
|
+
## Operational checklist
|
|
249
|
+
|
|
250
|
+
When changing authentication behavior, verify:
|
|
251
|
+
|
|
252
|
+
1. The Firebase Console providers and authorized domains are configured in both environments.
|
|
253
|
+
2. Email links return to `/auth/action` on the correct host and work in the same browser that initiated account linking.
|
|
254
|
+
3. Guest login creates one profile and does not emit Firestore permission errors after a previous guest deletion.
|
|
255
|
+
4. Guest deletion removes data, signs out locally, and lands on `/landing`.
|
|
256
|
+
5. Google and email-link upgrades preserve the existing UID and its progress.
|
|
257
|
+
6. Firestore listeners are torn down before sign-out, while the top-level auth observer remains active.
|
|
258
|
+
7. Route guards redirect unauthenticated users to landing and incomplete users to the appropriate onboarding stage.
|
|
259
|
+
8. `npm run lint`, `npm run build`, `npm run test`, and `npm run test:rules` pass before deployment.
|
|
260
|
+
|
|
261
|
+
## Related implementation references
|
|
262
|
+
|
|
263
|
+
- `src/app/core/store/auth/auth.store.ts`
|
|
264
|
+
- `src/app/core/firebase/firebase.service.ts`
|
|
265
|
+
- `src/app/core/firebase/email-link-context.service.ts`
|
|
266
|
+
- `src/app/core/auth/auth.service.ts`
|
|
267
|
+
- `src/app/core/auth/guards/`
|
|
268
|
+
- `src/app/main/account-profile/`
|
|
269
|
+
- `functions/src/index.ts`
|
|
270
|
+
- `firestore.rules`
|
|
@@ -219,25 +219,31 @@ Each `<entity>.mock.ts` exports a seed data array (e.g. `COMMUNITY_DB = [...]`).
|
|
|
219
219
|
|
|
220
220
|
## 6. Authentication & Access Flow
|
|
221
221
|
|
|
222
|
-
### 6.1
|
|
222
|
+
### 6.1 Authentication system
|
|
223
223
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
The generated application supports Google, passwordless email links, and anonymous guest
|
|
225
|
+
sessions. `AuthStore.afUser` holds the normalized Firebase `AuthSession`; `AuthStore.user`
|
|
226
|
+
resolves the matching Firestore application profile.
|
|
227
227
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
228
|
+
`AppComponent.ngOnInit()` starts one app-lifetime Firebase auth observer. Fresh sign-in
|
|
229
|
+
methods provision the profile directly after Firebase credentials are ready. Logout and
|
|
230
|
+
guest deletion tear down Firestore streams and reset application stores before invalidating
|
|
231
|
+
the local session.
|
|
232
|
+
|
|
233
|
+
See [`docs-infra/authentication-architecture.md`](authentication-architecture.md) for the
|
|
234
|
+
complete provider flows, same-browser email-link context, account linking, callable guest
|
|
235
|
+
deletion, Firestore rules, and deployment checklist.
|
|
233
236
|
|
|
234
237
|
### 6.2 Access Pipeline (Guards)
|
|
235
238
|
|
|
236
239
|
Users progress through access states defined in `AccessState`:
|
|
237
240
|
```
|
|
238
|
-
SUBMIT_INTEREST → WAITING →
|
|
241
|
+
SUBMIT_INTEREST → WAITING → CONSENT → DONE
|
|
239
242
|
```
|
|
240
243
|
|
|
244
|
+
When `environment.hasWaitlist` is `false`, interest submission moves directly from
|
|
245
|
+
`SUBMIT_INTEREST` to `CONSENT`.
|
|
246
|
+
|
|
241
247
|
The guard hierarchy is:
|
|
242
248
|
|
|
243
249
|
| Guard | Purpose |
|
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
"rules": "firestore.rules",
|
|
6
6
|
"indexes": "firestore.indexes.json"
|
|
7
7
|
},
|
|
8
|
+
"functions": {
|
|
9
|
+
"source": "functions",
|
|
10
|
+
"predeploy": [
|
|
11
|
+
"npm --prefix \"$RESOURCE_DIR\" run build"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
8
14
|
"hosting": {
|
|
9
15
|
"public": "dist/<%= dasherize(project) %>/browser",
|
|
10
16
|
"ignore": [
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"indexes": [
|
|
3
|
+
{
|
|
4
|
+
"collectionGroup": "userContexts",
|
|
5
|
+
"queryScope": "COLLECTION",
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"fieldPath": "__userId",
|
|
9
|
+
"order": "ASCENDING"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"fieldPath": "_deleted",
|
|
13
|
+
"order": "ASCENDING"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"fieldPath": "_updatedAt",
|
|
17
|
+
"order": "ASCENDING"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"fieldPath": "__name__",
|
|
21
|
+
"order": "ASCENDING"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"density": "SPARSE_ALL"
|
|
25
|
+
},
|
|
3
26
|
{
|
|
4
27
|
"collectionGroup": "users",
|
|
5
28
|
"queryScope": "COLLECTION",
|