Skip to content

docs(auth): provide auth DI tokens documentation #2809

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

Merged
merged 1 commit into from
Apr 24, 2021
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
112 changes: 112 additions & 0 deletions docs/auth/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,118 @@ export class AppComponent {
}
```

## Configuration with Dependency Injection

The AngularFireAuth Module provides several DI tokens to further configure your
authentication process.

### Configure

Using the `SETTINGS` DI Token (*default: null*), we can set the current Auth
instance's settings. This is used to edit/read configuration related options
like app verification mode for phone authentication, which is useful for
[testing](https://cloud.google.com/identity-platform/docs/test-phone-numbers).

```ts
import { SETTINGS as AUTH_SETTINGS } from '@angular/fire/auth';

@NgModule({
// ... Existing configuration
providers: [
// ... Existing Providers
{ provide: AUTH_SETTINGS, useValue: { appVerificationDisabledForTesting: true } },
]
})
export class AppModule { }
```

Read more at [Firebase Auth Settings](https://firebase.google.com/docs/reference/js/firebase.auth.AuthSettings).

### Use Current Browser Language

Using the `USE_DEVICE_LANGUAGE` DI Token (*default: null*), which is a boolean
that allow you to set the current language to the default device/browser
preference. This allows to localize emails but be aware that this only applies
if you use the standard template provided by Firebase.

```ts
import { USE_DEVICE_LANGUAGE } from '@angular/fire/auth';

@NgModule({
// ... Existing configuration
providers: [
// ... Existing Providers
{ provide: USE_DEVICE_LANGUAGE, useValue: true },
]
})
export class AppModule { }
```

If you want to set a different language, you can use `LANGUAGE_CODE` DI Token
(*default: null*).

More info at the [firebase auth docs](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#languagecode).

```ts
import { LANGUAGE_CODE } from '@angular/fire/auth';

@NgModule({
// ... Existing configuration
providers: [
// ... Existing Providers
{ provide: LANGUAGE_CODE, useValue: 'fr' },
]
})
export class AppModule { }
```

### Persistence

Firebase Auth default behavior is to persist a user's session even after the
user closes the browser. To change the current type of persistence on the
current Auth instance for the currently saved Auth session and apply this type
of persistence for future sign-in requests, including sign-in with redirect
requests, you can use the `PERSISTENCE` DI Token (*default: null*).

The possible types are `'local'`, `'session'` or `'none'`. Read more at
[authentication state persistence](https://firebase.google.com/docs/auth/web/auth-state-persistence),

```ts
import { PERSISTENCE } from '@angular/fire/auth';

@NgModule({
// ... Existing configuration
providers: [
// ... Existing Providers
{ provide: PERSISTENCE, useValue: 'session' },
]
})
export class AppModule { }
```

### Tenant

If you need to use multi-tenancy, you can set the current Auth instance's tenant
ID using `TENANT_ID` DI Token (*default: null*).

More tutorials regarding this topic are _coming soon_.

```ts
import { TENANT_ID } from '@angular/fire/auth';

@NgModule({
// ... Existing configuration
providers: [
// ... Existing Providers
{ provide: TENANT_ID, useValue: 'tenant-id-app-one' },
]
})
export class AppModule { }
```

- [Multi-Tenancy Authentication](https://cloud.google.com/identity-platform/docs/multi-tenancy-authentication)
- [Firebase Auth Tenant](https://firebase.google.com/docs/reference/js/firebase.auth.Auth#tenantid)

## UI Libraries

- Material Design : [ngx-auth-firebaseui](https://github.com/AnthonyNahas/ngx-auth-firebaseui)
Expand Down