UNPKG

11.1 kBJavaScriptView Raw
1
2import * as i0 from '@angular/core';
3import { InjectionToken, PLATFORM_ID, Injectable, Inject, Optional, NgModule } from '@angular/core';
4import { Subject, of, Observable, from, merge } from 'rxjs';
5import { observeOn, switchMap, map, shareReplay, first, switchMapTo, subscribeOn, filter } from 'rxjs/operators';
6import * as i1 from '@angular/fire';
7import { keepUnstableUntilFirst, VERSION } from '@angular/fire';
8import { ɵcacheInstance, ɵfirebaseAppFactory, ɵlazySDKProxy, FIREBASE_OPTIONS, FIREBASE_APP_NAME, ɵapplyMixins } from '@angular/fire/compat';
9import { isPlatformServer } from '@angular/common';
10import * as i2 from '@angular/fire/app-check';
11import firebase from 'firebase/compat/app';
12
13// DO NOT MODIFY, this file is autogenerated by tools/build.ts
14// Export a null object with the same keys as firebase/compat/auth, so Proxy can work with proxy-polyfill in Internet Explorer
15const 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
52const USE_EMULATOR = new InjectionToken('angularfire2.auth.use-emulator');
53const SETTINGS = new InjectionToken('angularfire2.auth.settings');
54const TENANT_ID = new InjectionToken('angularfire2.auth.tenant-id');
55const LANGUAGE_CODE = new InjectionToken('angularfire2.auth.langugage-code');
56const USE_DEVICE_LANGUAGE = new InjectionToken('angularfire2.auth.use-device-language');
57const PERSISTENCE = new InjectionToken('angularfire.auth.persistence');
58const ɵ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]);
80class 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 // HACK, as we're exporting auth.Auth, rather than auth, developers importing firebase.auth
93 // (e.g, `import { auth } from 'firebase/compat/app'`) are getting an undefined auth object unexpectedly
94 // as we're completely lazy. Let's eagerly load the Auth SDK here.
95 // There could potentially be race conditions still... but this greatly decreases the odds while
96 // we reevaluate the API.
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 // pipe in null authState to make credential zipable, just a weird devexp if
107 // authState and user go null to still have a credential
108 this.authState.pipe(filter(it => !it))).pipe(
109 // handle the { user: { } } when a user is already logged in, rather have null
110 // TODO handle the type corcersion better
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 // If they call a signIn or createUser function listen into the promise
116 // this will give us the user credential, push onto the logins Subject
117 // to be consumed in .credential
118 if (name.startsWith('signIn') || name.startsWith('createUser')) {
119 // TODO fix the types, the trouble is UserCredential has everything optional
120 val.then((user) => logins.next(user));
121 }
122 }
123 } });
124 }
125}
126AngularFireAuth.ɵ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 });
127AngularFireAuth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuth, providedIn: 'any' });
128i0.ɵɵ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
179class AngularFireAuthModule {
180 constructor() {
181 firebase.registerVersion('angularfire', VERSION.full, 'auth-compat');
182 }
183}
184AngularFireAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
185AngularFireAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule });
186AngularFireAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireAuthModule, providers: [AngularFireAuth] });
187i0.ɵɵ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 * Generated bundle index. Do not edit.
196 */
197
198export { AngularFireAuth, AngularFireAuthModule, LANGUAGE_CODE, PERSISTENCE, SETTINGS, TENANT_ID, USE_DEVICE_LANGUAGE, USE_EMULATOR, ɵauthFactory };
199//# sourceMappingURL=angular-fire-compat-auth.js.map