Я создал простое приложение для входа в систему с Ioni c и sqlitedb, я использовал sqlite в качестве хранилища, и как только пользователь вошел в приложение, он должен получить токен, перейти на домашнюю страницу, но впервые это происходит не перенаправлять на основе логического значения authenticationState
. Вот app.component.ts
, где создать базу данных и проверить состояние аутентификации.
export class AppComponent implements OnInit {
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private _authService: AuthenticationService,
private _router: Router,
private _storage: StorageService
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this._storage.createDb();
}).finally(() => {
this.checkAuth()
})
}
ngOnInit() {
}
private checkAuth() {
this._storage.getDatabaseState().subscribe((state) => {
console.log('DB state App component ', state)
if (state) {
this._authService.checkToken()
this._authService.getAuthState().subscribe((state) => {
console.log('App Componennt Auth State ', state)
if (state) {
this._router.navigate(['features'])
} else {
this._router.navigate(['intro'])
}
})
} else {
this._storage.createDb()
}
})
}
}
Что я здесь делаю не так?
Заранее спасибо.