From 9f88d4ebaff6aff87e93e4cfdcee7c04f3d40705 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marl=C3=A8ne=20SIMONDANT?= <msimondant@grandlyon.com>
Date: Wed, 26 Oct 2022 12:27:27 +0000
Subject: [PATCH] feat(auth) : all URLs requiring authentification redirect to
 login page (except /admin)

---
 src/app/app-routing.module.ts |  3 +--
 src/app/app.module.ts         |  2 --
 src/app/guards/auth.guard.ts  |  2 +-
 src/app/guards/login.guard.ts | 18 ------------------
 4 files changed, 2 insertions(+), 23 deletions(-)
 delete mode 100644 src/app/guards/login.guard.ts

diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index 5f82d11aa..32636a1d1 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -8,7 +8,6 @@ import { StructureListPrintComponent } from './form/orientation-form/component/s
 import { OrientationFormComponent } from './form/orientation-form/orientation-form.component';
 import { AdminGuard } from './guards/admin.guard';
 import { AuthGuard } from './guards/auth.guard';
-import { LoginGuard } from './guards/login.guard';
 import { LegalNoticeComponent } from './legal-notice/legal-notice.component';
 import { LoginComponent } from './login/login.component';
 import { NewsletterSubscriptionComponent } from './newsletter-subscription/newsletter-subscription.component';
@@ -167,7 +166,7 @@ const routes: Routes = [
     children: [
       {
         path: '',
-        canActivate: [LoginGuard],
+        canActivate: [AuthGuard],
         component: StructureExcludeComponent,
       },
       footerOutletRoute,
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 0e71f948f..0a57db88a 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -22,7 +22,6 @@ import { LegalNoticeComponent } from './legal-notice/legal-notice.component';
 import { PageComponent } from './page/page.component';
 import { ContactComponent } from './contact/contact.component';
 import { AuthGuard } from './guards/auth.guard';
-import { LoginGuard } from './guards/login.guard';
 import { CustomHttpInterceptor } from './config/http-interceptor';
 import { ResetEmailComponent } from './reset-email/reset-email.component';
 import { ResetPasswordComponent } from './reset-password/reset-password.component';
@@ -102,7 +101,6 @@ import { FilterModalComponent } from './annuaire/filter-modal/filter-modal.compo
     AuthGuard,
     AdminGuard,
     RoleGuard,
-    LoginGuard,
     DeactivateGuard,
     TempUserResolver,
     StructureResolver,
diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts
index d77c855f4..456ada45a 100644
--- a/src/app/guards/auth.guard.ts
+++ b/src/app/guards/auth.guard.ts
@@ -12,7 +12,7 @@ export class AuthGuard implements CanActivate {
     if (this.authService.isLoggedIn()) {
       return true;
     }
-    this.router.navigate(['/home'], { queryParams: { returnUrl: state.url } });
+    this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
     return false;
   }
 }
diff --git a/src/app/guards/login.guard.ts b/src/app/guards/login.guard.ts
deleted file mode 100644
index b2d8e5b7f..000000000
--- a/src/app/guards/login.guard.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
-import { Injectable } from '@angular/core';
-import { AuthService } from '../services/auth.service';
-/**
- * Guard to assert that we are logged in. Otherwise redirect to home
- */
-@Injectable()
-export class LoginGuard implements CanActivate {
-  constructor(private authService: AuthService, private router: Router) {}
-
-  canActivate(_next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
-    if (this.authService.isLoggedIn()) {
-      return true;
-    }
-    this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
-    return false;
-  }
-}
-- 
GitLab