feat: connect firebase emulator (#1196)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { initializeApp } from 'firebase/app';
|
import { initializeApp } from 'firebase/app';
|
||||||
import type { User } from 'firebase/auth';
|
import { connectAuthEmulator, User } from 'firebase/auth';
|
||||||
import {
|
import {
|
||||||
type Auth as FirebaseAuth,
|
type Auth as FirebaseAuth,
|
||||||
getAuth as getFirebaseAuth,
|
getAuth as getFirebaseAuth,
|
||||||
@@ -203,6 +203,9 @@ export function createGoogleAuth(bareAuth: KyInstance): GoogleAuth {
|
|||||||
return new GoogleAuth(bareAuth);
|
return new GoogleAuth(bareAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Connect emulators based on env vars
|
||||||
|
const envConnectEmulators = process.env.REACT_APP_FIREBASE_EMULATORS === 'true';
|
||||||
|
|
||||||
export const getAuthorizer = (googleAuth: GoogleAuth) => {
|
export const getAuthorizer = (googleAuth: GoogleAuth) => {
|
||||||
let _firebaseAuth: FirebaseAuth | null = null;
|
let _firebaseAuth: FirebaseAuth | null = null;
|
||||||
const logger = new DebugLogger('authorizer');
|
const logger = new DebugLogger('authorizer');
|
||||||
@@ -223,6 +226,12 @@ export const getAuthorizer = (googleAuth: GoogleAuth) => {
|
|||||||
});
|
});
|
||||||
_firebaseAuth = getFirebaseAuth(app);
|
_firebaseAuth = getFirebaseAuth(app);
|
||||||
}
|
}
|
||||||
|
if (envConnectEmulators && !(window as any).firebaseAuthEmulatorStarted) {
|
||||||
|
connectAuthEmulator(_firebaseAuth, 'http://localhost:9099', {
|
||||||
|
disableWarnings: true,
|
||||||
|
});
|
||||||
|
(window as any).firebaseAuthEmulatorStarted = true;
|
||||||
|
}
|
||||||
return _firebaseAuth;
|
return _firebaseAuth;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to initialize firebase', error);
|
logger.error('Failed to initialize firebase', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user