-
Notifications
You must be signed in to change notification settings - Fork 0
Firebase Authentication Setup
Jay Mathukiya edited this page Apr 14, 2025
·
1 revision
SoloType uses Firebase Authentication to handle user sign-up, sign-in, and session management.
-
Firebase Configuration (
lib/firebase/config.ts):- Initializes the Firebase application using credentials stored securely in environment variables (
.env.localfor local development, loaded from Azure App Settings in production). - Exports the necessary Firebase
authinstance for use throughout the application.
- Initializes the Firebase application using credentials stored securely in environment variables (
-
Authentication Context (
context/auth-context.tsx):- Provides a global context (
AuthProvider) that wraps the application (incomponents/client-layout.tsx). - Uses the
onAuthStateChangedlistener from the Firebase SDK to track the user's real-time authentication state. - Manages
user(Firebase User object or null) andloadingstate. - Exposes functions (
signIn,signUp,signInWithGoogle,signOut) via theuseAuthhook, which wrap the core Firebase SDK authentication methods. - Includes basic error handling.
- Provides a global context (
-
UI Integration:
-
Header (
components/header.tsx): Uses theuseAuthhook to conditionally display "Sign In"/"Sign Up" links (usingnext/link) or user information (email) and a "Sign Out" button/dropdown item. -
Login Page (
app/login/page.tsx): Contains a form that uses thesignInfunction from the context for email/password login and thesignInWithGooglefunction for Google Sign-In. Handles form state, errors, and redirection on success. -
Signup Page (
app/signup/page.tsx): Contains a form that uses thesignUpfunction from the context for email/password registration andsignInWithGoogle. Handles form state, errors, and redirection on success.
-
Header (
This setup allows users to authenticate using Email/Password or their Google account, with their session state managed centrally via the React Context and Firebase SDK.