GeezerVison is showing github.com — docs(app-check): explain App Check during server rendering by armando-navarro · Pull Request #3775 · angular/angularfire
Conversation
Fixes #3774
Refs #3256
Adds a "Server-side rendering" section to docs/app-check.md for the behavior #3773 introduced. #3773's development-mode warning links to this page.
Changes
- Explains that AngularFire does not create an App Check instance during server rendering, and that
inject(AppCheck) returns null there although its type says AppCheck.
- Explains that Firebase requests made during server rendering carry no App Check token, and links Firebase's recommended
appCheckToken route for products that enforce App Check.
- Shows the
APP_CHECK_ON_SERVER opt-in in a full app.config.server.ts.
- For 21.0.0-rc.1 and earlier, shows a browser-only config that keeps
provideAppCheck off the server, with inject(AppCheck, { optional: true }).
Verification
Followed the section literally in a new ng new --ssr Angular 21 app:
- 21.0.0-rc.1, the Dependency Injection setup as written:
ng build fails with ReferenceError: document is not defined, as the section says.
- 21.0.0-rc.1, the browser-only config: the build succeeds,
AppCheck is null on the server, and App Check starts in the browser.
- A canary built from
main after fix(app-check)!: skip App Check during server rendering by default #3773, the Dependency Injection setup as written: the build succeeds and AppCheck is null on the server.
- The same canary with the
APP_CHECK_ON_SERVER snippet as written: it compiles, and App Check runs on the server.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The App Check guide said nothing about server-rendered apps. angular#3773
stops AngularFire from creating an App Check instance during server
rendering, so the new section explains that inject(AppCheck) is null
there, that Firebase requests made while rendering carry no App Check
token, and how to opt back in with APP_CHECK_ON_SERVER. It also shows
a browser-only config for 21.0.0-rc.1 and earlier, where the guide's
setup fails with "document is not defined".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
The null-on-server behavior is covered by the toBeNull() specs in app-check.spec.ts, and CI ran them green on this branch. I did not rerun the rc.1 document is not defined case; I confirmed from source that 21.0.0-rc.1's app-check.module.ts has no server skip, which is consistent with it.
Optional, not blocking: #3773's dev-mode warning links here, but the section never uses the warning's wording, so a reader arriving from the console has nothing to match.
One flag on the hold: this approval alone makes it mergeable. Branch protection is an aggregator, so the approval is the only real gate.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The warning AngularFire prints during server rendering says it skips App Check there. The section now opens with the same words, so a reader arriving from the console finds them.
|
The section now opens with the warning's own words: "App Check's reCAPTCHA providers need a browser, so AngularFire skips App Check during server rendering."
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|