diff --git a/bizmatch/src/app/guards/auth.guard.ts b/bizmatch/src/app/guards/auth.guard.ts index 01bb7b7..48fd2bc 100644 --- a/bizmatch/src/app/guards/auth.guard.ts +++ b/bizmatch/src/app/guards/auth.guard.ts @@ -1,15 +1,27 @@ -import { Injectable } from '@angular/core'; +import { Injectable, PLATFORM_ID, Inject } from '@angular/core'; import { CanActivate, Router } from '@angular/router'; import { AuthService } from '../services/auth.service'; -import { createLogger } from '../utils/utils'; -const logger = createLogger('AuthGuard'); +import { isPlatformBrowser } from '@angular/common'; + @Injectable({ providedIn: 'root', }) export class AuthGuard implements CanActivate { - constructor(private authService: AuthService, private router: Router) {} + + constructor( + private authService: AuthService, + private router: Router, + @Inject(PLATFORM_ID) private platformId: Object + ) {} async canActivate(): Promise { + // 1. SSR CHECK: Wenn wir auf dem Server sind, immer erlauben! + // Der Server soll nicht redirecten, sondern einfach das HTML rendern. + if (!isPlatformBrowser(this.platformId)) { + return true; + } + + // 2. CLIENT CHECK: Das läuft nur im Browser const token = await this.authService.getToken(); if (token) { return true; diff --git a/bizmatch/src/environments/environment.prod.ts b/bizmatch/src/environments/environment.prod.ts index 94fe321..f449556 100644 --- a/bizmatch/src/environments/environment.prod.ts +++ b/bizmatch/src/environments/environment.prod.ts @@ -9,7 +9,7 @@ environment.production = true; environment.apiBaseUrl = 'https://api.bizmatch.net'; environment.mailinfoUrl = 'https://www.bizmatch.net'; -environment.imageBaseUrl = 'https://api.bizmatch.net'; // Ggf. auch auskommentieren, wenn Bilder lokal liegen +environment.imageBaseUrl = 'https://www.bizmatch.net';// Ggf. auch auskommentieren, wenn Bilder lokal liegen environment.POSTHOG_KEY = 'phc_eUIcIq0UPVzEDtZLy78klKhGudyagBz3goDlKx8SQFe'; environment.POSTHOG_HOST = 'https://eu.i.posthog.com'; \ No newline at end of file