Firebase Authentication Setup - jay-021/SoloType GitHub Wiki
Firebase Authentication Implementation
SoloType uses Firebase Authentication to handle user sign-up, sign-in, and session management.
Key Components
- Firebase Configuration (
lib/firebase/config.ts
):- Initializes the Firebase application using credentials stored securely in environment variables (
.env.local
for local development, loaded from Azure App Settings in production). - Exports the necessary Firebase
auth
instance 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
onAuthStateChanged
listener from the Firebase SDK to track the user's real-time authentication state. - Manages
user
(Firebase User object or null) andloading
state. - Exposes functions (
signIn
,signUp
,signInWithGoogle
,signOut
) via theuseAuth
hook, which wrap the core Firebase SDK authentication methods. - Includes basic error handling.
- Provides a global context (
- UI Integration:
- Header (
components/header.tsx
): Uses theuseAuth
hook 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 thesignIn
function from the context for email/password login and thesignInWithGoogle
function for Google Sign-In. Handles form state, errors, and redirection on success. - Signup Page (
app/signup/page.tsx
): Contains a form that uses thesignUp
function 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.