From 4906d431de74240b39dc100389cfb3a52958cb38 Mon Sep 17 00:00:00 2001 From: arolleaguekeng Date: Fri, 6 Feb 2026 01:34:59 +0100 Subject: [PATCH] refactor: remove mobile OAuth redirect flow and Firebase auth persistence configuration Remove isMobileDevice detection, handleRedirectResult method, and Router injection from AuthService. Revert loginWithGithub and loginWithGoogle to use only signInWithPopup for all devices. Remove browserLocalPersistence configuration from app.config.ts Firebase auth initialization. Remove unused imports: signInWithRedirect, getRedirectResult from @angular/fire/auth and Router from @angular/router. --- apps/main-dashboard/src/app/app.config.ts | 11 +--- .../app/modules/auth/services/auth.service.ts | 56 ++----------------- 2 files changed, 6 insertions(+), 61 deletions(-) diff --git a/apps/main-dashboard/src/app/app.config.ts b/apps/main-dashboard/src/app/app.config.ts index 7323c8eba..93bead458 100644 --- a/apps/main-dashboard/src/app/app.config.ts +++ b/apps/main-dashboard/src/app/app.config.ts @@ -11,7 +11,7 @@ import { provideAnimations } from '@angular/platform-browser/animations'; import { provideTranslateService, provideTranslateLoader } from '@ngx-translate/core'; import { provideTranslateHttpLoader } from '@ngx-translate/http-loader'; import { provideFirebaseApp, initializeApp } from '@angular/fire/app'; -import { provideAuth, getAuth, browserLocalPersistence, setPersistence } from '@angular/fire/auth'; +import { provideAuth, getAuth } from '@angular/fire/auth'; import { providePrimeNG } from 'primeng/config'; import { routes } from './app.routes'; import { environment } from '../environments/environment'; @@ -27,14 +27,7 @@ export const appConfig: ApplicationConfig = { provideHttpClient(withInterceptors([authInterceptor])), provideAnimations(), provideFirebaseApp(() => initializeApp(environment.firebase)), - provideAuth(() => { - const auth = getAuth(); - // Utiliser indexedDB au lieu de sessionStorage pour meilleure compatibilité mobile - setPersistence(auth, browserLocalPersistence).catch((error) => { - console.error('Erreur lors de la configuration de la persistance Firebase:', error); - }); - return auth; - }), + provideAuth(() => getAuth()), providePrimeNG({ theme: { preset: MyPreset, diff --git a/apps/main-dashboard/src/app/modules/auth/services/auth.service.ts b/apps/main-dashboard/src/app/modules/auth/services/auth.service.ts index 40f7bf0b8..7bed83931 100644 --- a/apps/main-dashboard/src/app/modules/auth/services/auth.service.ts +++ b/apps/main-dashboard/src/app/modules/auth/services/auth.service.ts @@ -1,6 +1,5 @@ import { HttpClient } from '@angular/common/http'; import { inject, Injectable, forwardRef } from '@angular/core'; -import { Router } from '@angular/router'; import { TokenService } from '../../../shared/services/token.service'; import { CookieService } from '../../../shared/services/cookie.service'; import { @@ -9,8 +8,6 @@ import { GoogleAuthProvider, signInWithEmailAndPassword, signInWithPopup, - signInWithRedirect, - getRedirectResult, signOut, user, User, @@ -23,7 +20,6 @@ import { environment } from '../../../../environments/environment'; }) export class AuthService { private auth = inject(Auth); - private router = inject(Router); user$: Observable; private http = inject(HttpClient); private tokenService = inject(forwardRef(() => TokenService)); @@ -33,34 +29,6 @@ export class AuthService { constructor() { this.user$ = user(this.auth); - this.handleRedirectResult(); - } - - /** - * Détecte si l'appareil est mobile - */ - private isMobileDevice(): boolean { - return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( - navigator.userAgent, - ); - } - - /** - * Gère le résultat de la redirection OAuth - */ - private async handleRedirectResult(): Promise { - try { - const result = await getRedirectResult(this.auth); - if (result?.user) { - console.log('Utilisateur authentifié via redirect, traitement du login...'); - await this.postLogin(result.user); - // Rediriger vers le dashboard après une authentification réussie - console.log('Navigation vers /console après authentification mobile réussie'); - await this.router.navigate(['/console']); - } - } catch (error) { - console.error('Erreur lors de la gestion du résultat de redirection:', error); - } } login(email: string, password: string): Observable { @@ -72,30 +40,14 @@ export class AuthService { async loginWithGithub() { const provider = new GithubAuthProvider(); - - if (this.isMobileDevice()) { - // Sur mobile, utiliser redirect pour éviter les problèmes de sessionStorage - await signInWithRedirect(this.auth, provider); - // Le résultat sera géré par handleRedirectResult() au prochain chargement - } else { - // Sur desktop, utiliser popup - const result = await signInWithPopup(this.auth, provider); - await this.postLogin(result.user); - } + const result = await signInWithPopup(this.auth, provider); + await this.postLogin(result.user); } async loginWithGoogle() { const provider = new GoogleAuthProvider(); - - if (this.isMobileDevice()) { - // Sur mobile, utiliser redirect pour éviter les problèmes de sessionStorage - await signInWithRedirect(this.auth, provider); - // Le résultat sera géré par handleRedirectResult() au prochain chargement - } else { - // Sur desktop, utiliser popup - const result = await signInWithPopup(this.auth, provider); - await this.postLogin(result.user); - } + const result = await signInWithPopup(this.auth, provider); + await this.postLogin(result.user); } private async postLogin(user: User) {