-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathauth.module.ts
More file actions
78 lines (71 loc) · 2.14 KB
/
auth.module.ts
File metadata and controls
78 lines (71 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {
EnvironmentProviders,
InjectionToken,
Injector,
NgModule,
NgZone,
Optional,
makeEnvironmentProviders,
} from '@angular/core';
import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire';
import { FirebaseApp, FirebaseApps } from '@angular/fire/app';
import { AppCheckInstances } from '@angular/fire/app-check';
import { registerVersion } from 'firebase/app';
import { Auth as FirebaseAuth } from 'firebase/auth';
import { AUTH_PROVIDER_NAME, Auth, AuthInstances } from './auth';
export const PROVIDED_AUTH_INSTANCES = new InjectionToken<Auth[]>('angularfire2.auth-instances');
export function defaultAuthInstanceFactory(provided: FirebaseAuth[]|undefined, defaultApp: FirebaseApp) {
const defaultAuth = ɵgetDefaultInstanceOf<FirebaseAuth>(AUTH_PROVIDER_NAME, provided, defaultApp);
return defaultAuth && new Auth(defaultAuth);
}
export function authInstanceFactory(fn: (injector: Injector) => FirebaseAuth) {
return (zone: NgZone, injector: Injector) => {
const auth = zone.runOutsideAngular(() => fn(injector));
return new Auth(auth);
};
}
const AUTH_INSTANCES_PROVIDER = {
provide: AuthInstances,
deps: [
[new Optional(), PROVIDED_AUTH_INSTANCES ],
]
};
const DEFAULT_AUTH_INSTANCE_PROVIDER = {
provide: Auth,
useFactory: defaultAuthInstanceFactory,
deps: [
[new Optional(), PROVIDED_AUTH_INSTANCES ],
FirebaseApp,
]
};
@NgModule({
providers: [
DEFAULT_AUTH_INSTANCE_PROVIDER,
AUTH_INSTANCES_PROVIDER,
]
})
export class AuthModule {
constructor() {
registerVersion('angularfire', VERSION.full, 'auth');
}
}
export function provideAuth(fn: (injector: Injector) => FirebaseAuth, ...deps: any[]): EnvironmentProviders {
registerVersion('angularfire', VERSION.full, 'auth');
return makeEnvironmentProviders([
DEFAULT_AUTH_INSTANCE_PROVIDER,
AUTH_INSTANCES_PROVIDER,
{
provide: PROVIDED_AUTH_INSTANCES,
useFactory: authInstanceFactory(fn),
multi: true,
deps: [
NgZone,
Injector,
ɵAngularFireSchedulers,
FirebaseApps,
[new Optional(), AppCheckInstances ],
...deps,
]
}
]);
}