From e48f1d91a45b88451e5c12ebd037c0734c0e1cf3 Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Sat, 7 Jun 2025 17:29:52 +0100 Subject: [PATCH] make auth resolver standalone --- client/src/app/app-routing.module.ts | 4 ++-- client/src/app/auth-resolver.service.ts | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 9b97f11..e8422f7 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -1,7 +1,7 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { AddNewTorrentComponent } from './add-new-torrent/add-new-torrent.component'; -import { AuthResolverService } from './auth-resolver.service'; +import { authResolver } from './auth-resolver.service'; import { LoginComponent } from './login/login.component'; import { MainLayoutComponent } from './main-layout/main-layout.component'; import { ProfileComponent } from './profile/profile.component'; @@ -23,7 +23,7 @@ const routes: Routes = [ path: '', component: MainLayoutComponent, resolve: { - isLoggedIn: AuthResolverService, + isLoggedIn: authResolver, }, children: [ { diff --git a/client/src/app/auth-resolver.service.ts b/client/src/app/auth-resolver.service.ts index 5fb8903..3371196 100644 --- a/client/src/app/auth-resolver.service.ts +++ b/client/src/app/auth-resolver.service.ts @@ -1,13 +1,7 @@ -import { Injectable } from '@angular/core'; +import { inject } from '@angular/core'; import { AuthService } from './auth.service'; +import { ResolveFn } from '@angular/router'; -@Injectable({ - providedIn: 'root', -}) -export class AuthResolverService { - constructor(private authService: AuthService) {} - - resolve() { - return this.authService.isLoggedIn(); - } -} +export const authResolver: ResolveFn = () => { + return inject(AuthService).isLoggedIn(); +};