-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using with Angular 17 SSR -> document is not defined on initializeAppCheck #3488
Comments
It's older Angular but here's an example on how to use AppCheck with SSR
|
Thanks James, I've managed to work around it for now by using provideAppCheck(() => {
// Don't initialise AppCheck if running in server
// Workaround for https://github.com/angular/angularfire/issues/3488
const platformId = inject(PLATFORM_ID);
if (isPlatformServer(platformId)) {
return;
}
let provider: CustomProvider | ReCaptchaV3Provider;
// Initialise AppCheck natively if running on iOS or Android
if (Capacitor.isNativePlatform()) {
// Set the web debug token to false if running on native
globalThis.FIREBASE_APPCHECK_DEBUG_TOKEN = false;
provider = new CustomProvider({
getToken: () =>
FirebaseAppCheck.getToken({
forceRefresh: true
}) as Promise<AppCheckToken>
});
} else {
// Or use ReCAPTCHAv3 if running in web
provider = new ReCaptchaV3Provider(
environment.firebase.recaptchaSiteKey
);
}
// Initialise AngularFire app check using provider
const appCheck = initializeAppCheck(getApp(), {
provider: provider
});
return appCheck;
}), Although now hitting a similar issue with Performance which the above doesn't seem to work for, so will raise that as a separate ticket |
Raised in #3489 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version info
Angular:
17.0.8
Firebase:
10.7.1
AngularFire:
17.0.0
Other (e.g. Ionic/Cordova, Node, browser, operating system):
Node 18, Ionic 7, MacOS
How to reproduce these conditions
Steps to set up and reproduce
ng add @angular/fire@17
ng add @angular/ssr
ng build
Debug output
Expected behavior
AngularFire should check if rendering on a browser before calling App Check code and RecaptchaV3 (which relies on
document
being available)Actual behavior
No check is done, so when providing App Check, this above error occurs as soon as pre-rendering on the server happens and
document
is accessed but isn't available due to not running in a browserThe text was updated successfully, but these errors were encountered: