feat: resume at origin path after login

Closes #168
This commit is contained in:
Jovan Krunić
2022-02-11 15:19:37 +01:00
parent 19b36c07b7
commit a5e5a5b407
5 changed files with 78 additions and 12 deletions

View File

@@ -1,9 +1,10 @@
import {Component, OnInit, OnDestroy} from '@angular/core';
import {NavController} from '@ionic/angular';
import {Router} from '@angular/router';
import {IAuthAction} from 'ionic-appauth';
import {AuthActions, IAuthAction} from 'ionic-appauth';
import {Subscription} from 'rxjs';
import {DefaultAuthService} from '../../default-auth.service';
import {AuthHelperService} from '../../auth-helper.service';
@Component({
selector: 'auth-callback',
@@ -17,6 +18,7 @@ export class AuthCallbackPageComponent implements OnInit, OnDestroy {
private auth: DefaultAuthService,
private navCtrl: NavController,
private router: Router,
private authHelper: AuthHelperService,
) {}
ngOnInit() {
@@ -28,7 +30,14 @@ export class AuthCallbackPageComponent implements OnInit, OnDestroy {
this.sub.unsubscribe();
}
async postCallback(_action: IAuthAction) {
await this.navCtrl.navigateRoot('profile');
async postCallback(action: IAuthAction) {
if (action.action === AuthActions.SignInSuccess) {
const originPath = await this.authHelper.getOriginPath();
this.navCtrl.navigateRoot(originPath ?? 'profile');
this.authHelper.deleteOriginPath();
}
if (action.action === AuthActions.SignInFailed) {
this.navCtrl.navigateRoot('profile');
}
}
}