make auth resolver standalone
This commit is contained in:
parent
2e7c97d023
commit
e48f1d91a4
2 changed files with 7 additions and 13 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
import { AddNewTorrentComponent } from './add-new-torrent/add-new-torrent.component';
|
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 { LoginComponent } from './login/login.component';
|
||||||
import { MainLayoutComponent } from './main-layout/main-layout.component';
|
import { MainLayoutComponent } from './main-layout/main-layout.component';
|
||||||
import { ProfileComponent } from './profile/profile.component';
|
import { ProfileComponent } from './profile/profile.component';
|
||||||
|
|
@ -23,7 +23,7 @@ const routes: Routes = [
|
||||||
path: '',
|
path: '',
|
||||||
component: MainLayoutComponent,
|
component: MainLayoutComponent,
|
||||||
resolve: {
|
resolve: {
|
||||||
isLoggedIn: AuthResolverService,
|
isLoggedIn: authResolver,
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { inject } from '@angular/core';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
|
import { ResolveFn } from '@angular/router';
|
||||||
|
|
||||||
@Injectable({
|
export const authResolver: ResolveFn<boolean> = () => {
|
||||||
providedIn: 'root',
|
return inject(AuthService).isLoggedIn();
|
||||||
})
|
};
|
||||||
export class AuthResolverService {
|
|
||||||
constructor(private authService: AuthService) {}
|
|
||||||
|
|
||||||
resolve() {
|
|
||||||
return this.authService.isLoggedIn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue