From 70343c2cc3fde961e066522facc4738b77b36482 Mon Sep 17 00:00:00 2001 From: Ian Labicani Date: Thu, 14 Mar 2024 22:14:24 +0800 Subject: [PATCH] Update imports and add authentication check in AppComponent --- src/app/app.component.ts | 18 ++++++++++++++---- src/app/app.config.ts | 2 +- ...elopement.ts => environment.development.ts} | 0 3 files changed, 15 insertions(+), 5 deletions(-) rename src/environments/{environment.developement.ts => environment.development.ts} (100%) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fd81e3c..1babc71 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,6 @@ -import { Component } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; +import { Component, OnInit, inject } from '@angular/core'; +import { Router, RouterOutlet } from '@angular/router'; +import { Auth } from '@angular/fire/auth'; import { environment } from '../environments/environment'; @Component({ @@ -9,9 +10,18 @@ import { environment } from '../environments/environment'; templateUrl: './app.component.html', styleUrl: './app.component.scss', }) -export class AppComponent { +export class AppComponent implements OnInit { + auth = inject(Auth); + router = inject(Router); + title = 'seawatch'; - constructor() { + + ngOnInit(): void { + this.auth.onAuthStateChanged((user) => { + if (!user) { + this.router.navigate(['/login']); + } + }); console.log(environment.production); } } diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 69abcb2..cd63a33 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -9,7 +9,7 @@ import { getFirestore, provideFirestore, } from '@angular/fire/firestore'; -import { environment } from '../environments/environment'; +import { environment } from '../environments/environment.development'; export const appConfig: ApplicationConfig = { providers: [ diff --git a/src/environments/environment.developement.ts b/src/environments/environment.development.ts similarity index 100% rename from src/environments/environment.developement.ts rename to src/environments/environment.development.ts