#136: EMail Auth on different browsers ...
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { FirebaseApp } from '@angular/fire/app';
|
||||
import { GoogleAuthProvider, UserCredential, createUserWithEmailAndPassword, getAuth, signInWithEmailAndPassword, signInWithPopup } from 'firebase/auth';
|
||||
import { GoogleAuthProvider, UserCredential, createUserWithEmailAndPassword, getAuth, signInWithCustomToken, signInWithEmailAndPassword, signInWithPopup } from 'firebase/auth';
|
||||
import { BehaviorSubject, Observable, catchError, firstValueFrom, map, of, shareReplay, take, tap } from 'rxjs';
|
||||
import { environment } from '../../environments/environment';
|
||||
import { MailService } from './mail.service';
|
||||
@@ -274,4 +274,31 @@ export class AuthService {
|
||||
return await this.refreshToken();
|
||||
}
|
||||
}
|
||||
|
||||
// Add this new method to sign in with a custom token
|
||||
async signInWithCustomToken(token: string): Promise<void> {
|
||||
try {
|
||||
// Sign in to Firebase with the custom token
|
||||
const userCredential = await signInWithCustomToken(this.auth, token);
|
||||
|
||||
// Store the authentication token
|
||||
if (userCredential.user) {
|
||||
const idToken = await userCredential.user.getIdToken();
|
||||
localStorage.setItem('authToken', idToken);
|
||||
localStorage.setItem('refreshToken', userCredential.user.refreshToken);
|
||||
|
||||
if (userCredential.user.photoURL) {
|
||||
localStorage.setItem('photoURL', userCredential.user.photoURL);
|
||||
}
|
||||
|
||||
// Load user role from the token
|
||||
this.loadRoleFromToken();
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error('Error signing in with custom token:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user