ds_firebase_auth_provider 0.0.2
ds_firebase_auth_provider: ^0.0.2 copied to clipboard
Firebase authentication provider for Dartstream.
Firebase Authentication Demo #
A complete sample application demonstrating Firebase Authentication integration with DartStream, featuring a Dart backend and modern web frontend.
๐ฏ Overview #
This demo showcases:
- Backend: Dart server using Shelf framework with Firebase Auth Provider
- Frontend: Modern web UI with glassmorphic design and Firebase branding
- Features: User registration, login, logout, and session management
- One-Command Launch: Start both backend and frontend together
Development Mode #
By default, the app runs in development mode which simulates Firebase authentication without requiring real Firebase credentials. This allows you to:
- Test the complete authentication flow
- See the UI and user experience
- Understand the API structure
- Demo the application without Firebase setup
To use real Firebase credentials, set kIsDev = false in bin/firebase_server.dart and provide actual Firebase environment variables.
๐ Prerequisites #
- Dart SDK 3.0.0 or higher
- Modern web browser (Chrome, Firefox, Edge, Safari)
- PowerShell (for Windows)
๐ Quick Start #
Option 1: One-Command Launch (Recommended) #
.\run_demo.ps1
This script will:
- Install all dependencies
- Start the backend server on port 8080
- Open the frontend in your default browser
- Display server logs in real-time
Option 2: Manual Launch #
Start Backend
# Install dependencies
dart pub get
# Run server
dart run bin/firebase_server.dart
Open Frontend
Open client/index.html in your web browser or use a local server:
# Using Python
python -m http.server 3000 --directory client
# Using Node.js
npx serve client
๐จ Features #
Backend API #
The server provides the following REST endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Health check |
| POST | /auth/register |
Create new user account |
| POST | /auth/login |
Sign in with email/password |
| GET | /auth/session |
Get current user session |
| POST | /auth/logout |
Sign out user |
Frontend Features #
- Modern UI: Glassmorphic design with Firebase branding
- Responsive: Works on desktop and mobile devices
- Animated: Smooth transitions and micro-animations
- Session Persistence: Automatic session restoration
- Error Handling: User-friendly error messages
- Real-time Feedback: Loading states and success alerts
๐ Usage Guide #
1. Register a New Account #
- Click "Create Account" button
- Enter your display name, email, and password
- Click "Create Account"
- You'll see a success message
2. Sign In #
- Enter your registered email and password
- Click "Sign In"
- You'll be redirected to the dashboard
3. View Dashboard #
After logging in, you'll see:
- Your display name and email
- Your user ID
- Authentication status
- Success confirmation
4. Sign Out #
Click the "Logout" button in the dashboard to sign out.
๐ง Configuration #
Environment Variables #
The backend supports the following environment variables for real Firebase configuration:
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_API_KEY=your-api-key
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
FIREBASE_MESSAGING_SENDER_ID=your-sender-id
FIREBASE_STORAGE_BUCKET=your-bucket
FIREBASE_APP_ID=your-app-id
FIREBASE_SERVICE_ACCOUNT_PATH=path/to/service-account.json
Note: If not provided, the app uses mock credentials for testing.
Using Real Firebase #
- Create a Firebase project at Firebase Console
- Enable Email/Password authentication
- Download service account key
- Set environment variables
- Restart the server
๐งช Testing #
Test Registration Flow #
$body = @{
email = 'test@example.com'
password = 'password123'
displayName = 'Test User'
} | ConvertTo-Json
Invoke-RestMethod -Uri 'http://localhost:8080/auth/register' -Method POST -Body $body -ContentType 'application/json'
Test Login Flow #
$body = @{
email = 'test@example.com'
password = 'password123'
} | ConvertTo-Json
Invoke-RestMethod -Uri 'http://localhost:8080/auth/login' -Method POST -Body $body -ContentType 'application/json'
Test Session Check #
$headers = @{
Authorization = 'Bearer YOUR_SESSION_ID'
}
Invoke-RestMethod -Uri 'http://localhost:8080/auth/session' -Method GET -Headers $headers
๐๏ธ Architecture #
Backend Structure #
example/
โโโ bin/
โ โโโ firebase_server.dart # Main server file
โโโ client/
โ โโโ index.html # Frontend HTML
โ โโโ styles.css # Styling
โ โโโ app.js # Frontend logic
โโโ pubspec.yaml # Dependencies
โโโ run_demo.ps1 # Launch script
Data Flow #
- Registration: Frontend โ POST /auth/register โ Firebase Provider โ Success
- Login: Frontend โ POST /auth/login โ Firebase Provider โ Session ID โ Frontend
- Session Check: Frontend โ GET /auth/session โ Validate Session โ User Data
- Logout: Frontend โ POST /auth/logout โ Clear Session โ Success
๐จ Design #
The frontend features:
- Firebase Colors: Orange (#FF6F00) and Yellow (#FFCA28)
- Dark Theme: Modern dark background with gradients
- Glassmorphism: Frosted glass effect with backdrop blur
- Animations: Smooth transitions and loading states
- Typography: Inter font family for clean readability
๐ Troubleshooting #
Server won't start #
- Check if port 8080 is already in use
- Ensure Dart SDK is properly installed
- Run
dart pub getto install dependencies
Frontend can't connect to backend #
- Verify server is running on http://localhost:8080
- Check browser console for CORS errors
- Ensure firewall isn't blocking the connection
Authentication errors #
- Check server logs for detailed error messages
- Verify Firebase credentials if using real Firebase
- Ensure email/password meet requirements (password min 6 chars)
๐ Additional Resources #
๐ License #
This example is part of the DartStream project and follows the same license.