Hi friends I need for help, weel I have LoginPage and TabsPage, so I want to show TabsPage after login and Hide TabsPage before to login my code
my app.component I have
const authObservable = this.afu.authState.subscribe( user => {
if(user) {
this.rootPage = 'TabsPage';
authObservable.unsubscribe();
} else {
this.rootPage = 'LoginPage';
authObservable.unsubscribe();
}
})
so when user to do login in my loginpage I have
login() {
if(this.form.form.valid)
this.auth.login(this.user)
.then((auth: any) => {
console.log(auth)
this.navCtrl.setRoot('TabsPage')
})
.catch((error: any) => {
..
});
}
auth.ts
login(user: User) {
return this.afu.auth.signInWithEmailAndPassword(user.email, user.password);
}
however when I to do Logout its to show the TabsPage in LoginPage
app.component.ts:
export class AppComponent {
// [root]="rootPage"
public rootPage: any = 'LoadingPage';
...
constructor(public config: Config,
public platform: Platform,
private authService: AuthService,
private swService: ServiceWorkerService,
private logger: LoggerService) {
this.initialiseApp();
}
private initialiseApp() {
...
this.authService.afAuth.authState.subscribe(user => {
if (user) {
this.rootPage = 'TabsPage';
} else {
this.rootPage = 'SignInPage';
}
}, () => {
this.rootPage = 'SignInPage';
});
}
sign-in.page.ts:
public signIn() {
const email = this.emailPasswordGroup.controls['email'].value;
const password = this.emailPasswordGroup.controls['password'].value;
this.authService.signInWithEmailAndPassword(email, password).then(() => {
this.navCtrl.setRoot('TabsPage');
}).catch((error) => {
...
});
}
auth.service.ts:
public signInWithEmailAndPassword(email: string, password: string): Promise<any> {
return this.afAuth.auth.signInWithEmailAndPassword(email, password);
}
Sign In:
Tabs:
1 Like
ohhh thanks my friend simply perfect, amazing, solved my problem, congratulations, now its work fine here (RESOLVED)