UNPKG

@serge-ivo/firestore-client

Version:
51 lines (50 loc) 1.94 kB
import { Auth, User, UserCredential, Unsubscribe } from "firebase/auth"; import { FirebaseApp } from "firebase/app"; export declare class AuthService { private readonly auth; private googleProvider; /** * Creates an instance of AuthService. * @param {FirebaseApp} app - The initialized Firebase App instance. * @throws Error if the FirebaseApp instance is not provided. */ constructor(app: FirebaseApp); /** * Gets the underlying Firebase Auth instance. * @returns {Auth} The Firebase Auth instance. */ getFirebaseAuth(): Auth; /** * Gets the currently signed-in user. * @returns {User | null} The current user object or null if not signed in. */ getCurrentUser(): User | null; /** * Gets the ID of the currently signed-in user. * @returns {string | null} The current user's ID or null if not signed in. */ getCurrentUserId(): string | null; /** * Signs in a user with email and password. * @param {string} email - The user's email. * @param {string} password - The user's password. * @returns {Promise<UserCredential>} A promise resolving to the user credential. */ signInWithEmailPassword(email: string, password: string): Promise<UserCredential>; /** * Initiates sign-in with Google using a popup. * @returns {Promise<UserCredential>} A promise resolving to the user credential. */ signInWithGoogle(): Promise<UserCredential>; /** * Signs out the current user. * @returns {Promise<void>} */ signOut(): Promise<void>; /** * Subscribes to changes in the user's authentication state. * @param {(user: User | null) => void} callback - Function to call when the auth state changes. * @returns {Unsubscribe} A function to unsubscribe from the listener. */ onAuthStateChanged(callback: (user: User | null) => void): Unsubscribe; }