Skip to content

Commit fa3cc66

Browse files
authored
Merge pull request #120 from onepanelio/fix/onepanel.core.334-login.redirect
fix: login redirect
2 parents 1c51e78 + 0530200 commit fa3cc66

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

src/app/auth/auth.guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@angular/core';
2-
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
2+
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
33
import { AuthService } from "./auth.service";
44

55
@Injectable({

src/app/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Injectable } from '@angular/core';
44
providedIn: 'root'
55
})
66
export class AuthService {
7-
public redirectUrl: string;
7+
public redirectUrl?: string;
88
private authToken?: string;
99

1010
get isLoggedIn(): boolean {

src/app/auth/login/login.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
<div class="op-info-box content">
33
<div class="font-proxima-bold font-size-larger color-primary">Log in</div>
44
<form class="mt-3" [formGroup]="form">
5-
<mat-form-field class="w-100" appearance="outline">
5+
<mat-form-field class="w-100 fix-mat-overflow" appearance="outline">
66
<mat-label>Token</mat-label>
77
<input matInput formControlName="token" />
88
<mat-error>{{tokenInput.getError('error')}}</mat-error>
99
</mat-form-field>
1010

11-
<div>
12-
<button mat-flat-button color="accent" class="op-rounded op-button border-secondary" (click)="login()">LOGIN</button>
13-
</div>
11+
<app-button (click)="login()" [loading]="loggingIn">
12+
LOGIN
13+
<span class="loading">LOGGING IN</span>
14+
</app-button>
1415
</form>
1516
</div>
1617
</div>

src/app/auth/login/login.component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { MatSnackBar } from "@angular/material/snack-bar";
1414
export class LoginComponent implements OnInit {
1515
form: FormGroup;
1616
tokenInput: AbstractControl;
17-
18-
redirectUrl = null;
17+
loggingIn = false;
1918

2019
constructor(
2120
private snackBar: MatSnackBar,
@@ -38,8 +37,8 @@ export class LoginComponent implements OnInit {
3837
this.snackBar.dismiss();
3938

4039
const state = history.state;
41-
if(state.referer) {
42-
this.redirectUrl = state.referer;
40+
if(state.referer && !this.authService.redirectUrl) {
41+
this.authService.redirectUrl = state.referer;
4342
}
4443
}
4544

@@ -49,6 +48,7 @@ export class LoginComponent implements OnInit {
4948
return;
5049
}
5150

51+
this.loggingIn = true;
5252
const tokenValue = this.tokenInput.value;
5353
const token = `Bearer ${tokenValue}`;
5454

@@ -58,14 +58,18 @@ export class LoginComponent implements OnInit {
5858

5959
this.namespaceTracker.getNamespaces();
6060

61-
if(this.redirectUrl) {
62-
this.appRouter.navigateByUrl(this.redirectUrl);
61+
if(this.authService.redirectUrl) {
62+
this.appRouter.navigateByUrl(this.authService.redirectUrl);
63+
this.authService.redirectUrl = null;
64+
this.loggingIn = false;
6365
return;
6466
}
6567

6668
this.appRouter.navigateToHomePage();
69+
this.loggingIn = false;
6770
}, err => {
6871
this.tokenInput.setErrors({error: 'Invalid token'})
72+
this.loggingIn = false;
6973
})
7074
}
7175
}

src/app/router/app-router.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export class AppRouter {
88

99
constructor(private router: Router) { }
1010

11+
public navigate(commands: any[], extras: NavigationExtras ) {
12+
return this.router.navigate(commands, extras);
13+
}
14+
15+
public navigateByUrl(url: string|UrlTree, extras?: NavigationExtras) {
16+
return this.router.navigateByUrl(url, extras);
17+
}
18+
1119
public navigateToRoot() {
1220
return this.router.navigate(['/']);
1321
}
@@ -43,8 +51,4 @@ export class AppRouter {
4351
public navigateToWorkspace(namespace: string, name: string) {
4452
return this.router.navigate(['/', namespace, 'workspaces', name]);
4553
}
46-
47-
public navigateByUrl(url: string|UrlTree, extras?: NavigationExtras) {
48-
return this.router.navigateByUrl(url, extras);
49-
}
5054
}

0 commit comments

Comments
 (0)