Skip to content

Commit

Permalink
feat: implement admin guard, add refuges skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolagobat committed Oct 20, 2023
1 parent 68d4144 commit 9ac5c69
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const routes: Routes = [
},
{
path: '',
redirectTo: 'home',
redirectTo: 'refuges',
pathMatch: 'full',
},
{
Expand All @@ -31,6 +31,13 @@ const routes: Routes = [
(m) => m.ProgrammingErrorPageModule,
),
},
{
path: 'refuges',
loadChildren: () =>
import('./pages/refuges/refuges/refuges.module').then(
(m) => m.RefugesPageModule,
),
},
];

@NgModule({
Expand Down
14 changes: 14 additions & 0 deletions app/src/app/guards/admin.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CanActivateFn, Router } from '@angular/router';
import { inject } from '@angular/core';
import { AuthService } from '../services/auth/auth.service';

export const adminGuard: CanActivateFn = async () => {
const authService = inject(AuthService);
const router = inject(Router);

if (await authService.isAuthenticated()) {
return true;
}

return router.parseUrl('/login');
};
3 changes: 1 addition & 2 deletions app/src/app/pages/login/login.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
label="Username"
labelPlacement="stacked"
[clearInput]="true"
placeholder="(+34) xxx xxx xxx"
type="tel"
placeholder="John Doe"
fill="outline"
[(ngModel)]="credentials.username"
name="username"
Expand Down
19 changes: 19 additions & 0 deletions app/src/app/pages/refuges/refuges/refuges-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { RefugesPage } from './refuges.page';
import { adminGuard } from '../../../guards/admin.guard';

const routes: Routes = [
{
path: '',
component: RefugesPage,
canActivate: [adminGuard],
},
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class RefugesPageRoutingModule {}
15 changes: 15 additions & 0 deletions app/src/app/pages/refuges/refuges/refuges.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

import { IonicModule } from '@ionic/angular';

import { RefugesPageRoutingModule } from './refuges-routing.module';

import { RefugesPage } from './refuges.page';

@NgModule({
imports: [CommonModule, FormsModule, IonicModule, RefugesPageRoutingModule],
declarations: [RefugesPage],
})
export class RefugesPageModule {}
13 changes: 13 additions & 0 deletions app/src/app/pages/refuges/refuges/refuges.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>refuges</ion-title>
</ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">refuges</ion-title>
</ion-toolbar>
</ion-header>
</ion-content>
Empty file.
17 changes: 17 additions & 0 deletions app/src/app/pages/refuges/refuges/refuges.page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RefugesPage } from './refuges.page';

describe('RefugesPage', () => {
let component: RefugesPage;
let fixture: ComponentFixture<RefugesPage>;

beforeEach(async(() => {
fixture = TestBed.createComponent(RefugesPage);
component = fixture.componentInstance;
fixture.detectChanges();
}));

it('should create', () => {
expect(component).toBeTruthy();
});
});
12 changes: 12 additions & 0 deletions app/src/app/pages/refuges/refuges/refuges.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-refuges',
templateUrl: './refuges.page.html',
styleUrls: ['./refuges.page.scss'],
})
export class RefugesPage implements OnInit {
constructor() {}

ngOnInit() {}
}

0 comments on commit 9ac5c69

Please sign in to comment.