switch (currentUserRole) {
case RolesEnum.ADMIN:
console.log('ADMIN CALL');
return col.snapshotChanges();
default:
console.log('NOT ADMIN CALL');
const queries = userTeamIds
.map((id) => {
return this.db.collection<Team>('teams', (ref: CollectionReference) => {
return ref.where(firebase.firestore.FieldPath.documentId(), '==', id);
}).snapshotChanges().pipe(map(s => {
console.log(s[0].type);
return s[0];
}));
});
return combineLatest(queries);
I am doing something like this, because I added some security rules for any user that is not an Admin
tap
rxjs operator) doesn't show any changes if I go and edit a document field on my teams collection
Observable<DocumentChangeAction<Team>>
, so I subscribed two arrow functions (onSuccess and onFailure) to see what's going on
this.db.collection<Team>('teams', (ref: CollectionReference) => ref.orderBy('updated_at', 'desc'));
but if any document HAS NO the field, RIP snapshotChanges D:
snapshotChanges()
will always retrieve the type as value
.
firebase.firestore.FieldPath.documentId()
on my where clause
doc().snapshotChanges()
has the above bug of always giving back type: "value"
instead of added | modified | removed
as stated on angularfire docs
Hi there
I have an async function which I would like to convert to an Observable stream (using rxjs operators). The await
calls must execute in the order they appear in the function.
async authenticateUser(profile: Profile): Promise<any> {
let authCookie: any;
try {
authCookie = await getCookie();
} catch (error) {
console.error(error);
}
if (!authCookie || authCookie?.length < 1) {
cancelAuthenticationCookieGet();
throw {message: "login failed", status: -2};
}
await saveProfileAsync(profile);
await storeCurrentAuthCookieAsync(authCookie);
storeSessionStorage();
await setPartitionSessionCookie(profile.url, authCookie);
}
Is there a clean way to accomplish the above?
cors
stuff I throw in the function, I am always getting “Same Origin Policy” error messages from the app when trying to reach out to it :( I’ve verified as much as I can (function exists on Firebase, URL matches on both ends, logs show the deployment), but no request ever reaches it.
Hello,
I'm trying to update an app and a home made library from angular 8.2 to angular 11.x.
My lib is in charge of authentication management which is based on Firebase Authentication.
Then I import this lib in my AppModule to manage the auth part, but I also use AngularFireDatabaseModule in this app.
Here is the app.module.ts
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { AngularFireModule } from '@angular/fire';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFireDatabaseModule } from '@angular/fire/database';
import { BrowserModule, BrowserTransferStateModule, Title } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LibCoreModule, ConfigService } from 'my-lib';
import { get } from 'lodash';
import { IntercomModule } from 'ng-intercom';
import { environment } from '../environments/environment';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { APP_CONFIG, APP_DI_CONFIG } from './app.config';
import { CgvModule } from './cgv';
import { CoreModule } from './core';
import { BrowserStateInterceptor } from './core/browserstate.interceptor';
import { CourseStatusResolver } from './core/service';
import { NotFoundComponent } from './not-found/not-found.component';
import { SharedModule } from './shared';
import { UrlRewritingComponent } from './url-rewriting/url-rewriting.component';
@NgModule({
declarations: [AppComponent, UrlRewritingComponent, NotFoundComponent],
imports: [
AppRoutingModule,
HttpClientModule,
BrowserTransferStateModule,
LibCoreModule.forRoot({
apiBase: environment.apiBase,
apiUrl: environment.apiUrl,
apiVersion: environment.apiVersion,
byPassAuth: false,
configUrl: `${environment.apiUrl}/${environment.apiBase}/${environment.apiVersion}/config`,
constantUrl: null,
ssrMock: environment.ssrMock,
error: {
'401Redirect': null,
'502Redirect': null
}
}),
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule,
BrowserAnimationsModule,
BrowserModule.withServerTransition({ appId: 'my-app' }),
CgvModule,
CoreModule,
SharedModule,
IntercomModule.forRoot({
appId: environment.intercom, // from your Intercom config
updateOnRouterChange: true, // will automatically run `update` on router event changes. Default: `false`
alignment: 'right'
})
],
providers: [
Title,
{
provide: APP_CONFIG,
useValue: APP_DI_CONFIG
},
{
provide: HTTP_INTERCEPTORS,
useClass: BrowserStateInterceptor,
multi: true
},
CourseStatusResolver,
BrowserTransferStateModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { RouterModule } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { AuthInterceptor } from './interceptors/auth.interceptor';
import { ErrorInterceptor } from './interceptors/error.interceptor';
import { LoaderInterceptor } from './interceptors/loader.interceptor';
import { ApiConfig } from './models/api-config.model';
import { AuthGuard } from './service/auth.guard';
import { InitializerService, load } from './service/initializer.service';
/** Http interceptor providers in outside-in order */
const httpInterceptorProviders = [
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true }
];
@NgModule({
imports: [
CommonModule,
HttpClientModule,
AngularFireAuthModule,
FormsModule,
RouterModule,
ReactiveFormsModule,
TranslateModule.forRoot({
isolate: true
}),
MatButtonModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatSnackBarModule
],
providers: [
ApiConfig,
AuthGuard,
{
provide: APP_INITIALIZER,
useFactory: load,
deps: [InitializerService],
multi: true
},
httpInterceptorProviders
]
})
export class LibCoreModule {
static forRoot(config: ApiConfig): ModuleWithProviders<LibCoreModule> {
return {
ngModule: LibCoreModule,
providers: [{ provide: ApiConfig, useValue: config }]
};
}
constructor() {}
}
Everything is compiling (without ivy enabled), but I got this error :
core.js:10756 Uncaught NullInjectorError: StaticInjectorError(AppModule)[InjectionToken angularfire2.app.options]:
StaticInjectorError(Platform: core)[InjectionToken angularfire2.app.options]:
NullInjectorError: No provider for InjectionToken angularfire2.app.options!
at NullInjector.get (http://localhost/vendor.js:48236:21)
at resolveToken (http://localhost/vendor.js:49192:20)
at tryResolveToken (http://localhost/vendor.js:49129:12)
at StaticInjector.get (http://localhost/vendor.js:49002:16)
at resolveToken (http://localhost/vendor.js:49192:20)
at tryResolveToken (http://localhost/vendor.js:49129:12)
at StaticInjector.get (http://localhost/vendor.js:49002:16)
at resolveNgModuleDep (http://localhost/vendor.js:63552:25)
at NgModuleRef_.get (http://localhost/vendor.js:64382:14)
at injectInjectorOnly (http://localhost/vendor.js:37859:29)
I've read plenty of stackoverflow, issues about this error, but nothing seems related to this problem, as it's always a lack of AngularFireModule.initializeApp(environment.firebase)
or bad usage of the lib.
AngularFireModule.initializeApp(environment.firebase)
inside LibCoreModule
in addition fo the one in AppModule
, or add it only on my lib. I always get the same error
ng add @angularfire/fire
and firebase init
, when I try to start the Firestore emulator (specifically - all the other ones appear to work fine), I get an error
Internal Error
and has the message Error: ShouldNotReachHere()
:D