redirect
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
import { authGuard } from './auth/auth.guard';
|
import { authGuard } from './auth/auth.guard';
|
||||||
|
import { unauthGuard } from './auth/unauth.guard';
|
||||||
import { LoginComponent } from './auth/login/login.component';
|
import { LoginComponent } from './auth/login/login.component';
|
||||||
import { RegisterComponent } from './auth/register/register.component';
|
import { RegisterComponent } from './auth/register/register.component';
|
||||||
import { AccountComponent } from './account/account.component';
|
import { AccountComponent } from './account/account.component';
|
||||||
@@ -10,10 +11,10 @@ import { TemplatesComponent } from './templates/templates.component';
|
|||||||
import { TemplateDetailComponent } from './templates/template-detail/template-detail.component';
|
import { TemplateDetailComponent } from './templates/template-detail/template-detail.component';
|
||||||
|
|
||||||
export const routes: Routes = [
|
export const routes: Routes = [
|
||||||
{ path: '', pathMatch: 'full', redirectTo: 'login' },
|
{ path: '', pathMatch: 'full', redirectTo: 'lists' },
|
||||||
{ path: 'login', component: LoginComponent },
|
{ path: 'login', component: LoginComponent, canActivate: [unauthGuard] },
|
||||||
{ path: 'register', component: RegisterComponent },
|
{ path: 'register', component: RegisterComponent, canActivate: [unauthGuard] },
|
||||||
{ path: 'verify-email', component: VerifyEmailComponent },
|
{ path: 'verify-email', component: VerifyEmailComponent, canActivate: [unauthGuard] },
|
||||||
{
|
{
|
||||||
path: 'auth',
|
path: 'auth',
|
||||||
children: [{ path: 'verify-email', component: VerifyEmailComponent }],
|
children: [{ path: 'verify-email', component: VerifyEmailComponent }],
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, inject } from '@angular/core';
|
import { Component, inject, OnInit } from '@angular/core';
|
||||||
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { Router, RouterLink } from '@angular/router';
|
import { Router, RouterLink } from '@angular/router';
|
||||||
import { finalize } from 'rxjs';
|
import { finalize } from 'rxjs';
|
||||||
@@ -29,7 +29,7 @@ import { OnboardingService } from '../../onboarding/onboarding.service';
|
|||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
styleUrl: '../auth-page.scss',
|
styleUrl: '../auth-page.scss',
|
||||||
})
|
})
|
||||||
export class LoginComponent {
|
export class LoginComponent implements OnInit {
|
||||||
private readonly auth = inject(AuthService);
|
private readonly auth = inject(AuthService);
|
||||||
private readonly formBuilder = inject(NonNullableFormBuilder);
|
private readonly formBuilder = inject(NonNullableFormBuilder);
|
||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
@@ -41,6 +41,12 @@ export class LoginComponent {
|
|||||||
password: ['', [Validators.required, Validators.minLength(8)]],
|
password: ['', [Validators.required, Validators.minLength(8)]],
|
||||||
});
|
});
|
||||||
protected loading = false;
|
protected loading = false;
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
if (this.auth.isAuthenticated()) {
|
||||||
|
void this.router.navigateByUrl('/lists');
|
||||||
|
}
|
||||||
|
}
|
||||||
protected resendingVerification = false;
|
protected resendingVerification = false;
|
||||||
protected hidePassword = true;
|
protected hidePassword = true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, inject } from '@angular/core';
|
import { Component, inject, OnInit } from '@angular/core';
|
||||||
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { NonNullableFormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { Router, RouterLink } from '@angular/router';
|
import { Router, RouterLink } from '@angular/router';
|
||||||
import { finalize } from 'rxjs';
|
import { finalize } from 'rxjs';
|
||||||
@@ -28,7 +28,7 @@ import { getAuthErrorMessage } from '../error-message';
|
|||||||
templateUrl: './register.component.html',
|
templateUrl: './register.component.html',
|
||||||
styleUrl: '../auth-page.scss',
|
styleUrl: '../auth-page.scss',
|
||||||
})
|
})
|
||||||
export class RegisterComponent {
|
export class RegisterComponent implements OnInit {
|
||||||
private readonly auth = inject(AuthService);
|
private readonly auth = inject(AuthService);
|
||||||
private readonly formBuilder = inject(NonNullableFormBuilder);
|
private readonly formBuilder = inject(NonNullableFormBuilder);
|
||||||
private readonly router = inject(Router);
|
private readonly router = inject(Router);
|
||||||
@@ -42,6 +42,12 @@ export class RegisterComponent {
|
|||||||
protected loading = false;
|
protected loading = false;
|
||||||
protected hidePassword = true;
|
protected hidePassword = true;
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
if (this.auth.isAuthenticated()) {
|
||||||
|
void this.router.navigateByUrl('/lists');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
submit(): void {
|
submit(): void {
|
||||||
if (this.form.invalid) {
|
if (this.form.invalid) {
|
||||||
this.form.markAllAsTouched();
|
this.form.markAllAsTouched();
|
||||||
|
|||||||
10
listify-client/src/app/auth/unauth.guard.ts
Normal file
10
listify-client/src/app/auth/unauth.guard.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { inject } from '@angular/core';
|
||||||
|
import { CanActivateFn, Router } from '@angular/router';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
|
||||||
|
export const unauthGuard: CanActivateFn = () => {
|
||||||
|
const auth = inject(AuthService);
|
||||||
|
const router = inject(Router);
|
||||||
|
|
||||||
|
return !auth.isAuthenticated() ? true : router.parseUrl('/lists');
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit, inject, signal } from '@angular/core';
|
import { Component, OnInit, inject, signal } from '@angular/core';
|
||||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
@@ -24,12 +24,18 @@ type VerificationState = 'loading' | 'success' | 'error' | 'missing-token';
|
|||||||
export class VerifyEmailComponent implements OnInit {
|
export class VerifyEmailComponent implements OnInit {
|
||||||
private readonly auth = inject(AuthService);
|
private readonly auth = inject(AuthService);
|
||||||
private readonly route = inject(ActivatedRoute);
|
private readonly route = inject(ActivatedRoute);
|
||||||
|
private readonly router = inject(Router);
|
||||||
|
|
||||||
protected readonly state = signal<VerificationState>('loading');
|
protected readonly state = signal<VerificationState>('loading');
|
||||||
protected readonly message = signal('E-Mail wird bestätigt.');
|
protected readonly message = signal('E-Mail wird bestätigt.');
|
||||||
protected readonly email = signal<string | null>(null);
|
protected readonly email = signal<string | null>(null);
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
if (this.auth.isAuthenticated()) {
|
||||||
|
void this.router.navigateByUrl('/lists');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const token = this.route.snapshot.queryParamMap.get('token');
|
const token = this.route.snapshot.queryParamMap.get('token');
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
|||||||
Reference in New Issue
Block a user