1 |
|
2 | import * as i0 from '@angular/core';
|
3 | import { InjectionToken, PLATFORM_ID, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
4 | import { Subject, of, Observable, from, merge } from 'rxjs';
|
5 | import { observeOn, switchMap, map, shareReplay, first, switchMapTo, subscribeOn, filter } from 'rxjs/operators';
|
6 | import * as i1 from '@angular/fire';
|
7 | import { keepUnstableUntilFirst, VERSION } from '@angular/fire';
|
8 | import { ɵcacheInstance, ɵfirebaseAppFactory, ɵlazySDKProxy, FIREBASE_OPTIONS, FIREBASE_APP_NAME, ɵapplyMixins } from '@angular/fire/compat';
|
9 | import { isPlatformServer } from '@angular/common';
|
10 | import * as i2 from '@angular/fire/app-check';
|
11 | import firebase from 'firebase/compat/app';
|
12 |
|
13 |
|
14 |
|
15 | const proxyPolyfillCompat = {
|
16 | name: null,
|
17 | config: null,
|
18 | emulatorConfig: null,
|
19 | app: null,
|
20 | applyActionCode: null,
|
21 | checkActionCode: null,
|
22 | confirmPasswordReset: null,
|
23 | createUserWithEmailAndPassword: null,
|
24 | currentUser: null,
|
25 | fetchSignInMethodsForEmail: null,
|
26 | isSignInWithEmailLink: null,
|
27 | getRedirectResult: null,
|
28 | languageCode: null,
|
29 | settings: null,
|
30 | onAuthStateChanged: null,
|
31 | onIdTokenChanged: null,
|
32 | sendSignInLinkToEmail: null,
|
33 | sendPasswordResetEmail: null,
|
34 | setPersistence: null,
|
35 | signInAndRetrieveDataWithCredential: null,
|
36 | signInAnonymously: null,
|
37 | signInWithCredential: null,
|
38 | signInWithCustomToken: null,
|
39 | signInWithEmailAndPassword: null,
|
40 | signInWithPhoneNumber: null,
|
41 | signInWithEmailLink: null,
|
42 | signInWithPopup: null,
|
43 | signInWithRedirect: null,
|
44 | signOut: null,
|
45 | tenantId: null,
|
46 | updateCurrentUser: null,
|
47 | useDeviceLanguage: null,
|
48 | useEmulator: null,
|
49 | verifyPasswordResetCode: null,
|
50 | };
|
51 |
|
52 | const USE_EMULATOR = new InjectionToken('angularfire2.auth.use-emulator');
|
53 | const SETTINGS = new InjectionToken('angularfire2.auth.settings');
|
54 | const TENANT_ID = new InjectionToken('angularfire2.auth.tenant-id');
|
55 | const LANGUAGE_CODE = new InjectionToken('angularfire2.auth.langugage-code');
|
56 | const USE_DEVICE_LANGUAGE = new InjectionToken('angularfire2.auth.use-device-language');
|
57 | const PERSISTENCE = new InjectionToken('angularfire.auth.persistence');
|
58 | const ɵauthFactory = (app, zone, useEmulator, tenantId, languageCode, useDeviceLanguage, settings, persistence) => ɵcacheInstance(`${app.name}.auth`, 'AngularFireAuth', app.name, () => {
|
59 | const auth = zone.runOutsideAngular(() => app.auth());
|
60 | if (useEmulator) {
|
61 | auth.useEmulator(...useEmulator);
|
62 | }
|
63 | if (tenantId) {
|
64 | auth.tenantId = tenantId;
|
65 | }
|
66 | auth.languageCode = languageCode;
|
67 | if (useDeviceLanguage) {
|
68 | auth.useDeviceLanguage();
|
69 | }
|
70 | if (settings) {
|
71 | for (const [k, v] of Object.entries(settings)) {
|
72 | auth.settings[k] = v;
|
73 | }
|
74 | }
|
75 | if (persistence) {
|
76 | auth.setPersistence(persistence);
|
77 | }
|
78 | return auth;
|
79 | }, [useEmulator, tenantId, languageCode, useDeviceLanguage, settings, persistence]);
|
80 | class AngularFireAuth {
|
81 | constructor(options, name,
|
82 | // tslint:disable-next-line:ban-types
|
83 | platformId, zone, schedulers, useEmulator, // can't use the tuple here
|
84 | settings, // can't use firebase.auth.AuthSettings here
|
85 | tenantId, languageCode, useDeviceLanguage, persistence, _appCheckInstances) {
|
86 | const logins = new Subject();
|
87 | const auth = of(undefined).pipe(observeOn(schedulers.outsideAngular), switchMap(() => zone.runOutsideAngular(() => import('firebase/compat/auth'))), map(() => ɵfirebaseAppFactory(options, zone, name)), map(app => ɵauthFactory(app, zone, useEmulator, tenantId, languageCode, useDeviceLanguage, settings, persistence)), shareReplay({ bufferSize: 1, refCount: false }));
|
88 | if (isPlatformServer(platformId)) {
|
89 | this.authState = this.user = this.idToken = this.idTokenResult = this.credential = of(null);
|
90 | }
|
91 | else {
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | const _ = auth.pipe(first()).subscribe();
|
98 | const redirectResult = auth.pipe(switchMap(auth => auth.getRedirectResult().then(it => it, () => null)), keepUnstableUntilFirst, shareReplay({ bufferSize: 1, refCount: false }));
|
99 | const authStateChanged = auth.pipe(switchMap(auth => new Observable(sub => ({ unsubscribe: zone.runOutsideAngular(() => auth.onAuthStateChanged(next => sub.next(next), err => sub.error(err), () => sub.complete())) }))));
|
100 | const idTokenChanged = auth.pipe(switchMap(auth => new Observable(sub => ({ unsubscribe: zone.runOutsideAngular(() => auth.onIdTokenChanged(next => sub.next(next), err => sub.error(err), () => sub.complete())) }))));
|
101 | this.authState = redirectResult.pipe(switchMapTo(authStateChanged), subscribeOn(schedulers.outsideAngular), observeOn(schedulers.insideAngular));
|
102 | this.user = redirectResult.pipe(switchMapTo(idTokenChanged), subscribeOn(schedulers.outsideAngular), observeOn(schedulers.insideAngular));
|
103 | this.idToken = this.user.pipe(switchMap(user => user ? from(user.getIdToken()) : of(null)));
|
104 | this.idTokenResult = this.user.pipe(switchMap(user => user ? from(user.getIdTokenResult()) : of(null)));
|
105 | this.credential = merge(redirectResult, logins,
|
106 |
|
107 |
|
108 | this.authState.pipe(filter(it => !it))).pipe(
|
109 |
|
110 |
|
111 | map(credential => (credential === null || credential === void 0 ? void 0 : credential.user) ? credential : null), subscribeOn(schedulers.outsideAngular), observeOn(schedulers.insideAngular));
|
112 | }
|
113 | return ɵlazySDKProxy(this, auth, zone, { spy: {
|
114 | apply: (name, _, val) => {
|
115 |
|
116 |
|
117 |
|
118 | if (name.startsWith('signIn') || name.startsWith('createUser')) {
|
119 |
|
120 | val.then((user) => logins.next(user));
|
121 | }
|
122 | }
|
123 | } });
|
124 | }
|
125 | }
|
126 | AngularFireAuth.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuth, deps: [{ token: FIREBASE_OPTIONS }, { token: FIREBASE_APP_NAME, optional: true }, { token: PLATFORM_ID }, { token: i0.NgZone }, { token: i1.ɵAngularFireSchedulers }, { token: USE_EMULATOR, optional: true }, { token: SETTINGS, optional: true }, { token: TENANT_ID, optional: true }, { token: LANGUAGE_CODE, optional: true }, { token: USE_DEVICE_LANGUAGE, optional: true }, { token: PERSISTENCE, optional: true }, { token: i2.AppCheckInstances, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
127 | AngularFireAuth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuth, providedIn: 'any' });
|
128 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuth, decorators: [{
|
129 | type: Injectable,
|
130 | args: [{
|
131 | providedIn: 'any'
|
132 | }]
|
133 | }], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
134 | type: Inject,
|
135 | args: [FIREBASE_OPTIONS]
|
136 | }] }, { type: undefined, decorators: [{
|
137 | type: Optional
|
138 | }, {
|
139 | type: Inject,
|
140 | args: [FIREBASE_APP_NAME]
|
141 | }] }, { type: Object, decorators: [{
|
142 | type: Inject,
|
143 | args: [PLATFORM_ID]
|
144 | }] }, { type: i0.NgZone }, { type: i1.ɵAngularFireSchedulers }, { type: undefined, decorators: [{
|
145 | type: Optional
|
146 | }, {
|
147 | type: Inject,
|
148 | args: [USE_EMULATOR]
|
149 | }] }, { type: undefined, decorators: [{
|
150 | type: Optional
|
151 | }, {
|
152 | type: Inject,
|
153 | args: [SETTINGS]
|
154 | }] }, { type: undefined, decorators: [{
|
155 | type: Optional
|
156 | }, {
|
157 | type: Inject,
|
158 | args: [TENANT_ID]
|
159 | }] }, { type: undefined, decorators: [{
|
160 | type: Optional
|
161 | }, {
|
162 | type: Inject,
|
163 | args: [LANGUAGE_CODE]
|
164 | }] }, { type: undefined, decorators: [{
|
165 | type: Optional
|
166 | }, {
|
167 | type: Inject,
|
168 | args: [USE_DEVICE_LANGUAGE]
|
169 | }] }, { type: undefined, decorators: [{
|
170 | type: Optional
|
171 | }, {
|
172 | type: Inject,
|
173 | args: [PERSISTENCE]
|
174 | }] }, { type: i2.AppCheckInstances, decorators: [{
|
175 | type: Optional
|
176 | }] }]; } });
|
177 | ɵapplyMixins(AngularFireAuth, [proxyPolyfillCompat]);
|
178 |
|
179 | class AngularFireAuthModule {
|
180 | constructor() {
|
181 | firebase.registerVersion('angularfire', VERSION.full, 'auth-compat');
|
182 | }
|
183 | }
|
184 | AngularFireAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
185 | AngularFireAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule });
|
186 | AngularFireAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule, providers: [AngularFireAuth] });
|
187 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule, decorators: [{
|
188 | type: NgModule,
|
189 | args: [{
|
190 | providers: [AngularFireAuth]
|
191 | }]
|
192 | }], ctorParameters: function () { return []; } });
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 | export { AngularFireAuth, AngularFireAuthModule, LANGUAGE_CODE, PERSISTENCE, SETTINGS, TENANT_ID, USE_DEVICE_LANGUAGE, USE_EMULATOR, ɵauthFactory };
|
199 |
|