idk
This commit is contained in:
parent
4c9a23c547
commit
d4c44ec3ed
2 changed files with 8 additions and 10 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { Component, inject, OnInit } from '@angular/core';
|
import { Component, inject } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
FormBuilder,
|
FormBuilder,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
|
@ -6,7 +6,7 @@ import {
|
||||||
Validators,
|
Validators,
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import AuthService from '../../../service/auth.service';
|
import AuthService from '../../../service/auth.service';
|
||||||
import { AuthResponse, Token } from '../../../models';
|
import { AuthResponse } from '../../../models';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -14,7 +14,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||||
imports: [ReactiveFormsModule],
|
imports: [ReactiveFormsModule],
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
})
|
})
|
||||||
export default class LoginComponent implements OnInit {
|
export default class LoginComponent {
|
||||||
fb: FormBuilder = inject(FormBuilder);
|
fb: FormBuilder = inject(FormBuilder);
|
||||||
authService: AuthService = inject(AuthService);
|
authService: AuthService = inject(AuthService);
|
||||||
router: Router = inject(Router);
|
router: Router = inject(Router);
|
||||||
|
@ -25,12 +25,6 @@ export default class LoginComponent implements OnInit {
|
||||||
password: [null, [Validators.required]],
|
password: [null, [Validators.required]],
|
||||||
});
|
});
|
||||||
|
|
||||||
returnUrl: string | undefined;
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
|
||||||
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/dashboard';
|
|
||||||
}
|
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
if (this.form.invalid) {
|
if (this.form.invalid) {
|
||||||
console.log(this.form.errors);
|
console.log(this.form.errors);
|
||||||
|
@ -41,7 +35,10 @@ export default class LoginComponent implements OnInit {
|
||||||
localStorage.setItem('access_token', r.accessToken);
|
localStorage.setItem('access_token', r.accessToken);
|
||||||
localStorage.setItem('refresh_token', r.refreshToken);
|
localStorage.setItem('refresh_token', r.refreshToken);
|
||||||
|
|
||||||
this.router.navigate([this.returnUrl]);
|
const returnUrl =
|
||||||
|
this.route.snapshot.queryParams['returnUrl'] || '/dashboard';
|
||||||
|
|
||||||
|
this.router.navigate([returnUrl]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ export const authGuard: CanActivateFn = (route, state) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
router.navigate(['/auth/login'], {
|
router.navigate(['/auth/login'], {
|
||||||
queryParams: { returnUrl: state.url },
|
queryParams: { returnUrl: state.url },
|
||||||
|
skipLocationChange: true,
|
||||||
});
|
});
|
||||||
return of(false);
|
return of(false);
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue