mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 00:52:55 +00:00
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {
|
||||
CanActivate,
|
||||
NavigationExtras,
|
||||
Router,
|
||||
RouterStateSnapshot,
|
||||
} from '@angular/router';
|
||||
import {DefaultAuthService} from './default-auth.service';
|
||||
import {PAIAAuthService} from './paia/paia-auth.service';
|
||||
import {IAuthService} from 'ionic-appauth';
|
||||
@@ -33,7 +38,14 @@ export class AuthGuardService implements CanActivate {
|
||||
try {
|
||||
await this.authService.getValidToken();
|
||||
} catch {
|
||||
this.router.navigate(['profile']);
|
||||
const originNavigation = this.router.getCurrentNavigation();
|
||||
let extras: NavigationExtras = {};
|
||||
if (originNavigation) {
|
||||
const url = originNavigation.extractedUrl.toString();
|
||||
extras = {queryParams: {origin_path: url}};
|
||||
}
|
||||
this.router.navigate(['profile'], extras);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
SCUserConfigurationMap,
|
||||
} from '@openstapps/core';
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
const AUTH_ORIGIN_PATH = 'stapps.auth.origin_path';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -21,6 +23,7 @@ export class AuthHelperService {
|
||||
constructor(
|
||||
private translateService: TranslateService,
|
||||
private configProvider: ConfigProvider,
|
||||
private storageProvider: StorageProvider,
|
||||
) {
|
||||
this.userConfigurationMap = (
|
||||
this.configProvider.getAnyValue('auth') as {
|
||||
@@ -62,4 +65,22 @@ export class AuthHelperService {
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async deleteOriginPath() {
|
||||
return this.storageProvider.delete(AUTH_ORIGIN_PATH);
|
||||
}
|
||||
|
||||
async setOriginPath(path: string) {
|
||||
return this.storageProvider.put<string>(AUTH_ORIGIN_PATH, path);
|
||||
}
|
||||
|
||||
async getOriginPath() {
|
||||
let originPath: string;
|
||||
try {
|
||||
originPath = await this.storageProvider.get<string>(AUTH_ORIGIN_PATH);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
return originPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {PAIAAuthService} from '../../paia-auth.service';
|
||||
import {AuthHelperService} from '../../../auth-helper.service';
|
||||
|
||||
@Component({
|
||||
selector: 'auth-callback',
|
||||
@@ -17,6 +18,7 @@ export class PAIAAuthCallbackPageComponent implements OnInit, OnDestroy {
|
||||
private auth: PAIAAuthService,
|
||||
private navCtrl: NavController,
|
||||
private router: Router,
|
||||
private authHelper: AuthHelperService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -28,7 +30,14 @@ export class PAIAAuthCallbackPageComponent implements OnInit, OnDestroy {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
|
||||
async postCallback(_action: IAuthAction) {
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user