firebaseui-angular
Version:
[](https://github.com/RaphaelJenni/FirebaseUI-Angular/actions/workflows/firebaseui-angular.yml/badge.svg) [ • 10.4 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, Inject, Optional, EventEmitter, Component, Output, NgModule } from '@angular/core';
import * as firebaseui$1 from 'firebaseui';
import { ɵfirebaseAppFactory as _firebaseAppFactory, FIREBASE_OPTIONS, FIREBASE_APP_NAME } from '@angular/fire/compat';
import * as i1 from '@angular/fire/compat/auth';
import { USE_EMULATOR } from '@angular/fire/compat/auth';
import 'firebase/compat/auth';
import firebaseOriginal from 'firebase/compat/app';
import { CommonModule } from '@angular/common';
class FirebaseuiAngularLibraryService {
constructor(options, nameOrConfig, _useEmulator, // can't use the tuple here
zone) {
// noinspection JSNonASCIINames
const app = _firebaseAppFactory(options, zone, nameOrConfig);
const useEmulator = _useEmulator;
if (!window.firebaseUiInstance) {
const auth = app.auth();
if (useEmulator) {
const connectionString = useEmulator[0].startsWith('http') ? useEmulator[0] : `http://${useEmulator.join(':')}`;
auth.useEmulator(connectionString);
}
window.firebaseUiInstance = new firebaseui$1.auth.AuthUI(auth);
}
// store the firebaseui instance on the window object to prevent double initialization
this.firebaseUiInstance = window.firebaseUiInstance;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseuiAngularLibraryService, deps: [{ token: FIREBASE_OPTIONS }, { token: FIREBASE_APP_NAME, optional: true }, { token: USE_EMULATOR, optional: true }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseuiAngularLibraryService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseuiAngularLibraryService, decorators: [{
type: Injectable
}], ctorParameters: () => [{ type: undefined, decorators: [{
type: Inject,
args: [FIREBASE_OPTIONS]
}] }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [FIREBASE_APP_NAME]
}] }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [USE_EMULATOR]
}] }, { type: i0.NgZone }] });
class FirebaseuiAngularLibraryComponent {
static { this.COMPUTED_CALLBACKS = 'COMPUTED_CALLBACKS'; }
constructor(angularFireAuth, _firebaseUiConfig, _firebaseUiConfig_Feature, ngZone, firebaseUIService) {
this.angularFireAuth = angularFireAuth;
this._firebaseUiConfig = _firebaseUiConfig;
this._firebaseUiConfig_Feature = _firebaseUiConfig_Feature;
this.ngZone = ngZone;
this.firebaseUIService = firebaseUIService;
this.signInSuccessWithAuthResultCallback = new EventEmitter(); // tslint:disable-line
this.signInFailureCallback = new EventEmitter(); // tslint:disable-line
this.uiShownCallback = new EventEmitter(); // tslint:disable-line
}
get firebaseUiConfig() {
return {
...this._firebaseUiConfig,
...this._firebaseUiConfig_Feature
};
}
ngOnInit() {
this.subscription = this.angularFireAuth.authState.subscribe((value) => {
if ((value && value.isAnonymous) || !value) {
if (this.firebaseUiConfig.signInOptions.length !== 0) {
this.firebaseUIPopup();
}
else {
throw new Error('There must be at least one AuthProvider.');
}
}
});
}
ngOnDestroy() {
if (!!this.subscription) {
this.subscription.unsubscribe();
}
}
getUIAuthConfig() {
if (!this.firebaseUiConfig.callbacks) {
this._firebaseUiConfig[FirebaseuiAngularLibraryComponent.COMPUTED_CALLBACKS] = true;
this._firebaseUiConfig.callbacks = this.getCallbacks();
}
return this.firebaseUiConfig;
}
firebaseUIPopup() {
const firebaseUiInstance = this.firebaseUIService.firebaseUiInstance;
const uiAuthConfig = this.getUIAuthConfig();
// Check if callbacks got computed to reset them again after providing the to firebaseui.
// Necessary for allowing updating the firebaseui config during runtime.
let resetCallbacks = false;
if (uiAuthConfig[FirebaseuiAngularLibraryComponent.COMPUTED_CALLBACKS]) {
resetCallbacks = true;
delete uiAuthConfig[FirebaseuiAngularLibraryComponent.COMPUTED_CALLBACKS];
}
// show the firebaseui
firebaseUiInstance.start('#firebaseui-auth-container', uiAuthConfig);
if (resetCallbacks) {
this._firebaseUiConfig.callbacks = null;
}
}
getCallbacks() {
const signInSuccessWithAuthResultCallback = (authResult, redirectUrl) => {
this.ngZone.run(() => {
this.signInSuccessWithAuthResultCallback.emit({
authResult,
redirectUrl
});
});
return this.firebaseUiConfig.signInSuccessUrl;
};
const signInFailureCallback = (error) => {
this.ngZone.run(() => {
this.signInFailureCallback.emit({
code: error.code,
credential: error.credential
});
});
return Promise.reject();
};
const uiShownCallback = () => {
this.ngZone.run(() => {
this.uiShownCallback.emit();
});
};
return {
signInSuccessWithAuthResult: signInSuccessWithAuthResultCallback,
signInFailure: signInFailureCallback,
uiShown: uiShownCallback
};
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseuiAngularLibraryComponent, deps: [{ token: i1.AngularFireAuth }, { token: 'firebaseUIAuthConfig' }, { token: 'firebaseUIAuthConfigFeature' }, { token: i0.NgZone }, { token: FirebaseuiAngularLibraryService }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.12", type: FirebaseuiAngularLibraryComponent, isStandalone: true, selector: "firebase-ui", outputs: { signInSuccessWithAuthResultCallback: "signInSuccessWithAuthResult", signInFailureCallback: "signInFailure", uiShownCallback: "uiShown" }, ngImport: i0, template: '<div id="firebaseui-auth-container"></div>', isInline: true }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseuiAngularLibraryComponent, decorators: [{
type: Component,
args: [{
selector: 'firebase-ui',
template: '<div id="firebaseui-auth-container"></div>',
standalone: true
}]
}], ctorParameters: () => [{ type: i1.AngularFireAuth }, { type: undefined, decorators: [{
type: Inject,
args: ['firebaseUIAuthConfig']
}] }, { type: undefined, decorators: [{
type: Inject,
args: ['firebaseUIAuthConfigFeature']
}] }, { type: i0.NgZone }, { type: FirebaseuiAngularLibraryService }], propDecorators: { signInSuccessWithAuthResultCallback: [{
type: Output,
args: ['signInSuccessWithAuthResult']
}], signInFailureCallback: [{
type: Output,
args: ['signInFailure']
}], uiShownCallback: [{
type: Output,
args: ['uiShown']
}] } });
/*
* Created by Raphael Jenni
* Copyright (c) 2017 Raphael Jenni
*/
const firebase = firebaseOriginal;
const firebaseui = firebaseui$1;
class FirebaseUISignInSuccessWithAuthResult {
}
class FirebaseUISignInFailure {
}
class FirebaseUIModule {
static forRoot(firebaseUiAuthConfig) {
return {
ngModule: FirebaseUIModule,
providers: [
{ provide: 'firebaseUIAuthConfig', useValue: firebaseUiAuthConfig },
{ provide: 'firebaseUIAuthConfigFeature', useValue: {} }
]
};
}
static forFeature(firebaseUIAuthConfig) {
return {
ngModule: FirebaseUIModule,
providers: [
{ provide: 'firebaseUIAuthConfigFeature', useValue: firebaseUIAuthConfig }
]
};
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseUIModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.12", ngImport: i0, type: FirebaseUIModule, imports: [CommonModule,
FirebaseuiAngularLibraryComponent], exports: [FirebaseuiAngularLibraryComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseUIModule, providers: [FirebaseuiAngularLibraryService], imports: [CommonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.12", ngImport: i0, type: FirebaseUIModule, decorators: [{
type: NgModule,
args: [{
imports: [
CommonModule,
FirebaseuiAngularLibraryComponent
],
providers: [FirebaseuiAngularLibraryService],
exports: [FirebaseuiAngularLibraryComponent]
}]
}] });
/*
* Public API Surface of firebaseui-angular-library
*/
/**
* Generated bundle index. Do not edit.
*/
export { FirebaseUIModule, FirebaseUISignInFailure, FirebaseUISignInSuccessWithAuthResult, FirebaseuiAngularLibraryComponent, FirebaseuiAngularLibraryService, firebase, firebaseui };
//# sourceMappingURL=firebaseui-angular.mjs.map