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) {