Firebase Auth & AngularFire Not Working on IOS Device - ios

I created an Ionic 5 + Capacitor + Firebase project and added the latest version of AngularFire to it.
Everything works perfectly on Desktop but when I launch on my iPhone, there is an error (Well, there is no error but the redirection of my first page does not work).
So, no error in the logs but a white screen.
After much research, I came to the following conclusion.
I use AngularFireAuthGuard as follows :
{
path: '',
loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule),
...canActivate(() => redirectUnauthorizedTo(['landing']))
}
And my research made me realize that with latest version of AngularFire firebase Auth is not detected properly.
So I found a piece of code that solved the problem for me for a while :
import { Component } from '#angular/core';
import { Capacitor } from '#capacitor/core';
import { initializeApp } from 'firebase/app';
import { indexedDBLocalPersistence, initializeAuth } from 'firebase/auth';
import { environment } from 'src/environments/environment';
#Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
})
export class AppComponent {
constructor() {
const app = initializeApp(environment.firebase);
if (Capacitor.isNativePlatform) {
initializeAuth(app, {
persistence: indexedDBLocalPersistence
});
}
}
}
As soon as I wanted to add the onAuthStateChanged in my app.component I got the following error :
auth/already-initialized
In my opinion, it might be because my app.module.ts looks like this :
#NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
IonicStorageModule.forRoot(),
AppRoutingModule,
AngularFireAuthModule,
AngularFireModule.initializeApp(environment.firebase)
],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
My application is initialized here but if I delete it I get another injection error...
Do you have any ideas how I can fix the problem ?

Wondering if my problem is similarly related: signin link works on web and android, but in iOS the app opens, I see the link is received but then the signInWithEmailLink() promise neither resolves nor catches.
This is the code; I see the console.log and thereafter there's silence:
console.log(`incoming Passwordless Login Link for mail ${email}: ${uri}, ${originalLink}`);
signInWithEmailLink(this.auth, email, originalLink)
.then(cred => {
console.log("successfully logged in", email, cred);
window.localStorage.removeItem("emailForSignIn");
this.router.navigateByUrl("/home");
})
.catch((err) => {
console.error("signInLink err", JSON.stringify(err));
this.ngZone.run(() => this.router.navigateByUrl("/pwlsignup"));
});
After the call I do see a few lines of these though, looking into if it is related:
nw_protocol_boringssl_get_output_frames(1301) [C4.1:2][0x7fee0fe19300] get output frames failed, state 8196
2018-11-12 22:12:05.398615-0800 QQBCHAT[37807:7011607] TIC Read Status [4:0x0]: 1:57
EDIT: Yes, mine must be a different issue - and I found the solution too, just if anyone hits this with google search
https://github.com/angular/angularfire/issues/2979#issuecomment-940910213
import {
getAuth,
indexedDBLocalPersistence,
initializeAuth,
provideAuth,
} from '#angular/fire/auth';
#NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
...
provideAuth(() => {
if (Capacitor.isNativePlatform()) {
return initializeAuth(getApp(), {
persistence: indexedDBLocalPersistence,
});
} else {
return getAuth();
}
}),
]
})

Related

error adding app-routing.module in stackblitz

Here: https://stackblitz.com/edit/partehoras?file=src/app/app.module.ts
When I add App Roting like I do it in my VS Code local project without any problem
In package.json
I get this error: "Error in src/app/app.module.ts (5:34)
Cannot find module './app-routing.module' or its corresponding type declarations."
Any idea, please?
Thanks
You already have RouterModule.forRoot([]) imported in the app module, I am assuming you want to move to a separate file, if so, you need to create a file in the same folder as the app module with the name app-routing.module.ts and add the following code
import { RouterModule, Routes } from '#angular/router';
import { ListadoEmpleadosComponent } from './empleados/listado-empleados/listado-empleados.component';
import { NgModule } from '#angular/core';
export const routes: Routes = [
{ path: 'empleados', component: ListadoEmpleadosComponent },
{ path: '', redirectTo: 'empleados', pathMatch: 'full' },
{ path: '**', redirectTo: 'empleados', pathMatch: 'full' },
];
#NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
P.S. if you generate an angular app using the angular CLI you will get a prompt to create app routing module which will create the file automatically.

Angular 8: No component factory found for the component-even added in app.module.ts

I am trying to migrate the project from Angular 7 to Angular 8.
However, getting the below error for the HeaderComponent after upgrading to Angular 8.
zone.js:199 Uncaught Error: No component factory found for HeaderComp. Did you add it to #NgModule.entryComponents?
at noComponentFactoryError (core.js:17988)
at CodegenComponentFactoryResolver.push../node_modules/#angular/core/fesm5/core.js.CodegenComponentFactoryResolver.resolveComponentFactory (core.js:18026)
at CodegenComponentFactoryResolver.push../node_modules/#angular/core/fesm5/core.js.CodegenComponentFactoryResolver.resolveComponentFactory (core.js:18023)
at AngularFrameworkComponentWrapper.push../node_modules/ag-grid-angular/dist/angularFrameworkComponentWrapper.js.AngularFrameworkComponentWrapper.createComponent (angularFrameworkComponentWrapper.js:65)
at DynamicAgNg2Component.createComponent (angularFrameworkComponentWrapper.js:44)
at DynamicAgNg2Component.push../node_modules/ag-grid-angular/dist/angularFrameworkComponentWrapper.js.BaseGuiComponent.init (angularFrameworkComponentWrapper.js:84)
at DynamicAgNg2Component.init (angularFrameworkComponentWrapper.js:40)
at UserComponentFactory.push../node_modules/ag-grid-community/dist/lib/components/framework/userComponentFactory.js.UserComponentFactory.initComponent (userComponentFactory.js:371)
at UserComponentFactory.push../node_modules/ag-grid-community/dist/lib/components/framework/userComponentFactory.js.UserComponentFactory.createAndInitUserComponent (userComponentFactory.js:121)
at UserComponentFactory.push../node_modules/ag-grid-community/dist/lib/components/framework/userComponentFactory.js.UserComponentFactory.newHeaderComponent (userComponentFactory.js:37)
Please find the HeaderComponent and app.module.ts below.
This is for Angular 8 so it was working in Angular 7 and after my searches on Google I improved app.module.ts by declaring entryComponent.
HeaderComponent.ts:
import { Component, OnInit, OnDestroy, Inject, forwardRef, Input } from
'#angular/core';
import { pagesToggleService } from '../../services/toggler.service'
import { Subscriber } from 'rxjs/Subscriber'
declare var pg: any;
#Component({
selector: 'pg-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit, OnDestroy {
_headerClass = "";
isHorizontalLayout: false;
_service;
#Input()
boxed: boolean = false;
#Input()
extraClass: string = "";
constructor(private toggler: pagesToggleService) {
}
ngOnInit() {
this.isHorizontalLayout = pg.isHorizontalLayout;
this._service = this.toggler.headerClass
.subscribe(state => {
this._headerClass = state;
});
}
ngOnDestroy() {
this._service.unsubscribe()
}
}
app.module.ts:
#NgModule({
declarations: [
HeaderComponent
]
entryComponents: [
HeaderComponent
]
I expect it to work in Angular 8 but it is throwing 'No component factory found for HeaderComp.' error.
Please help me to find a solution.
Thanks,
Kind Regards.
Begum
In declaration part add first the app component in app.module.ts like :
#NgModule({
declarations: [AppComponent,HeaderComponent],
entryComponents: [HeaderComponent]
})
Thanks
The error says the HeadComp instead of HeaderComponent so it is a grid issue and I fixed it by using ngx-datatable in html.

Why does the QR Scanner Ionic plugin generate an error?

EDIT: I managed to make the plugin work, but when I test the app on my iPhone and click the button, Xcode sends me a warning: THREAD WARNING: ['QRScanner'] took '468.501953' ms. Plugin should use a background thread.
I tried so many things and follow so many articles and tutorials (also here, on SO) to get rid of this. I'm building an Ionic app, using the QR Scanner plugin that this framework provides. My app.module.ts is:
// Here are the basic Ionic import statements.
// Eventually, I import the plugin to scan QR codes.
import { QRScanner, QRScannerStatus } from '#ionic-native/qr-scanner';
#NgModule({
declarations: [ MyApp, HomePage ],
imports: [ BrowserModule, IonicModule.forRoot(MyApp) ],
bootstrap: [IonicApp],
entryComponents: [ MyApp, HomePage ],
providers: [ StatusBar, SplashScreen, QRScanner,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule { }
The folder structure is:
My app has only one page, HomePage, and the content of the src/pages/home/home.ts file is:
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { QRScanner, QRScannerStatus } from '#ionic-native/qr-scanner';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private qrScanner: QRScanner) { }
scanQrCode() {
this.qrScanner.prepare().then((status: QRScannerStatus) => {
if (status.authorized) {
let scanSub = this.qrScanner.scan().subscribe((text: string) => { console.log('Scanned something', text);
this.qrScanner.hide();
scanSub.unsubscribe();
});
} else if (status.denied) {
// ...
} else {
// ...
}
}).catch((e: any) => console.log('Error is', e));
}
}
Inside the src/pages/home/home.html file, I have:
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button (click)="scanQrCode()"></button>
</ion-content>
I build the app and run it on my iPhone 5, but when I click the button to scan a code, Xcode sends this: Error is [Object object]. Do you know why?

Ionic - Problems displaying AdMob banner/interstitial (iOS)

There are no issues what so ever showing both banner and interstitial ads on Android devices but on iOS devices they somehow don't show, only blank box in footer area and no popup appears - however works perfectly fine on the emulator, displaying test ads.
In AdMob - I have created only one app (iOS) and therefor only have two Ad Unit IDs(Banner and Interstitial) which I use, can that be the issue or ?
You can see my code below:
import { Component } from '#angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { AdMobFree, AdMobFreeBannerConfig, AdMobFreeInterstitialConfig } from '#ionic-native/admob-free';
import { ProjectlistPage } from '../pages/projectlist/projectlist';
#Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = ProjectlistPage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private admobFree : AdMobFree) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
this.showAdmobBannerAds();
this.showAdmobInterstitialAds();
});
}
showAdmobBannerAds(){
const bannerConfig: AdMobFreeBannerConfig = {
id: 'ca-app-pub-xxxxxx',
isTesting: false,
autoShow: true,
};
this.admobFree.banner.config(bannerConfig);
this.admobFree.banner.prepare()
.then(() => {
this.admobFree.banner.show();
})
.catch(e => console.log(e));
}
showAdmobInterstitialAds(){
const interstitialConfig: AdMobFreeInterstitialConfig = {
id: 'ca-app-pub-xxxxxx',
isTesting: false,
autoShow: true,
};
this.admobFree.interstitial.config(interstitialConfig);
this.admobFree.interstitial.prepare()
.then(() => {
this.admobFree.interstitial.show();
})
.catch(e => console.log(e));
}
}
Anyone have any suggestions ?
Thanks.
This issue got resolved by adjusting payment details within AdMob to reflect 100% my companies DUNS info.
https://github.com/ratson/cordova-plugin-admob-free/issues/157#issuecomment-374006844

Angular 2 routing not working with ASP.net core MVC

i'm working in an ASP.NET Core Web Application, using Angular 2 and VS 2015 as IDE. This is totally new for me, so i've been following every tutorial to get this page work. When i finally put everything together i face a routing problem: The page stays in the loading... tag and never show the content in the ModuleViewComponent. Read a lot of stackoverflow questions but I could not fix it.
My main.ts file looks like this:
// main entry point
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
the app.module.ts
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { FormsModule } from '#angular/forms';
import { HttpModule } from '#angular/http';
import { RouterModule, Routes } from '#angular/router';
import { NgForm } from '#angular/forms';
import { AppComponent } from './app.component';
import { ModuleViewComponent } from './components/CommonComponents/moduleView.component/moduleView.component';
const myRoutes: Routes = [
{
path: 'home',
component: ModuleViewComponent
},
{
path: '/',
redirectTo: 'home',
pathMatch: 'full'
}
];
#NgModule({
imports: [
RouterModule.forRoot(myRoutes),
BrowserModule,
FormsModule,
HttpModule
],
declarations: [
AppComponent,
NavbarComponent,
ModuleViewComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '#angular/core';
#Component({
selector: 'my-app',
template:'<router-outlet></router-outlet>'
})
export class AppComponent {
}
And the index.cshtml
#{
ViewData["Title"] = "Home Page";
}
<my-app>loading...</my-app>
How can i get this to work and show the component content? Any help is more than welcome, thanks in advance.
I have created a sample application which explains step by step details to create angular (Angular v4) applications with Asp.net MVC framework. Below is the link. Hope this helps you. You have to update route config file in your project so that angular can receive requests.
http://hive.rinoy.in/angular4-and-asp-net-mvc-hybrid-application/
http://hive.rinoy.in/routing-in-angular-asp-net-mvc-application/

Resources