Skip to content
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

FirebaseServerApp documentation #3529

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,39 @@ Update the imports from `import { ... } from 'firebase/auth'` to `import { ... }

[Getting Started](https://firebase.google.com/docs/auth/web/start) | [API Reference](https://firebase.google.com/docs/reference/js/auth)

## Server-side Rendering

To support Auth context in server-side rendering, you can provide `FirebaseServerApp`:

```ts
import { ApplicationConfig, PLATFORM_ID, inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { provideFirebaseApp, initializeApp, initializeServeApp, initializeServerApp } from '@angular/fire/app';
import { provideAuth, getAuth } from '@angular/fire/auth';

export const appConfig: ApplicationConfig = {
providers: [
provideFirebaseApp(() => {
if (isPlatformBrowser(inject(PLATFORM_ID))) {
return initializeApp(firebaseConfig);
}
// Optional, since it's null in dev-mode and SSG
const request = inject(REQUEST, { optional: true });
const authIdToken = request?.headers.authorization?.split("Bearer ")[1];
return initializeServerApp(firebaseConfig, {
authIdToken,
releaseOnDeref: request || undefined
});
}),
provideAuth(() => getAuth(inject(FirebaseApp)),
...
],
...
})
```

Follow Firebase's [ Session Management with Service Workers documentation](https://firebase.google.com/docs/auth/web/service-worker-sessions) to learn how to pass the `idToken` to the server. __Note: this will not currently work in dev-mode as Angular SSR does not provide a method to get the Request headers.__

## Convenience observables

AngularFire provides observables to allow convenient use of the Firebase Authentication with RXJS.
Expand Down
Loading