A React application with multi-provider authentication support (Firebase, Supabase, Appwrite).
src/
βββ assets/
β βββ react.svg
βββ components/
β βββ DeleteAccount.jsx # Account deletion modal
β βββ ForgotPassword.jsx # Password reset modal
β βββ LoadingSpinner.jsx # Loading animation
β βββ ProtectedRoute.jsx # Auth route wrapper
βββ pages/
β βββ AuthPage.jsx # Login/Signup page
β βββ DashboardPage.jsx # User dashboard
β βββ LandingPage.jsx # Home page
βββ services/
β βββ api/ # API service layer
β β βββ auth.service.js
β β βββ blog.service.js
β β βββ storage.service.js
β βββ config/ # Provider configurations
β β βββ appwrite.config.js
β β βββ firebase.config.js
β β βββ supabase.config.js
β βββ lib/ # Core functionality
β βββ auth.js # Auth provider class
β βββ database.js # Database operations
βββ store/ # Redux state management
β βββ actions/
β β βββ authActions.js
β βββ slices/
β β βββ authSlice.js
β βββ index.js
βββ App.jsx # Root component
βββ index.css # Global styles
βββ main.jsx # Entry point
- Multi-provider authentication (Firebase/Supabase/Appwrite)
- Protected routes
- User management (login/signup/delete)
- Social auth (Google/GitHub)
- Password reset
- Email verification
- Account deletion
-
React
-
Redux Toolkit
-
React Router
-
Tailwind CSS
-
Framer Motion
-
Dirst the use r will land in the landing page
-
Then the user will be redirected to the auth page
-
After the user is authenticated, the user will be redirected to the dashboard
The AuthPage component is the central authentication page managing both login and signup flows. It supports multiple authentication providers (Firebase, Supabase, Appwrite) and offers social sign-in options (Google and GitHub). Below is an outline of its logic flow and key functionalities with code examples.
-
Purpose:
- Handles user authentication (login/signup) via email and password.
- Provides OAuth options (Google and GitHub).
- Enables provider selection (Firebase, Supabase, Appwrite) to streamline multi-provider setups.
- Redirects authenticated users to the dashboard.
-
Key Features:
- Auth Check on Mount: Automatically checks if a user is already authenticated.
- Dynamic Form Mode: Allows toggling between Login and Signup.
- Provider Selection: Lets users choose an authentication provider.
- Error & Loading Handling: Displays errors and a loading spinner during async operations.
- Password Reset: Includes a modal for password reset functionality.
-
Authentication Check on Component Mount
- A
useEffecthook dispatches thecheckAuthaction to verify if the user is already logged in. - If authenticated, the user is immediately redirected to the dashboard.
useEffect(() => { const checkAuthState = async () => { try { const currentUser = await dispatch(checkAuth()); if (currentUser) { navigate('/dashboard'); } } catch (error) { console.error('Auth check failed:', error); } }; checkAuthState(); }, [dispatch, navigate]);
- A
-
State Management
- Uses local state to manage inputs:
email,password, and UI toggles (isSignup,showForgotPassword). - Uses Redux for global states such as
user,loading,error, and the selectedprovider.
- Uses local state to manage inputs:
-
Provider Selection
- Renders a grid of buttons representing each authentication provider.
- Clicking a provider button updates the Redux state with the selected provider.
const providers = [ { id: 'firebase', name: 'Firebase', icon: 'π₯', options: [ ... ] }, { id: 'supabase', name: 'Supabase', icon: 'β‘', options: [ ... ] }, { id: 'appwrite', name: 'Appwrite', icon: 'π', options: [ ... ] } ]; // Button example (inside JSX): <button onClick={() => dispatch(setProvider(p.id))}> <span>{p.icon}</span> <span>{p.name}</span> </button>
-
Form Submission & Authentication Handling
- The form submission is handled by
handleSubmit, which:- Prevents the default event.
- Validates that a provider is selected.
- Dispatches either
loginUserorsignupUserbased on the current mode. - Redirects the user to
/dashboardupon successful authentication. - Sets an error message if authentication fails.
const handleSubmit = async (e) => { e.preventDefault(); if (!provider) { dispatch(setError('Please select a database provider')); return; } dispatch(setError(null)); try { const result = await dispatch(isSignup ? signupUser(email, password) : loginUser(email, password)); if (result) navigate('/dashboard'); } catch (err) { dispatch(setError(isSignup ? 'Signup failed' : 'Invalid credentials')); } };
- The form submission is handled by
-
OAuth Login Handling
- Separate functions handle social login via Google and GitHub:
- Dispatch
loginWithGoogleorloginWithGithubwith the selected provider. - Redirect to
/dashboardon success.
- Dispatch
const handleGoogleLogin = async () => { try { await dispatch(loginWithGoogle(provider)); navigate('/dashboard'); } catch (err) {} }; const handleGithubLogin = async () => { try { await dispatch(loginWithGithub(provider)); navigate('/dashboard'); } catch (err) {} };
- Separate functions handle social login via Google and GitHub:
-
Password Reset Flow
- A "Forgot Password?" link toggles the display of the
ForgotPasswordmodal. - It passes a callback to close the modal (
onClose={() => setShowForgotPassword(false)}).
- A "Forgot Password?" link toggles the display of the
-
Loading State:
When an authentication process is ongoing, a spinner is displayed:if (loading) { return ( <div className="min-h-screen flex items-center justify-center bg-gradient-to-br ..."> <div className="animate-spin w-12 h-12 border-4 ... rounded-full" /> </div> ); }
-
Error Alerts:
If there's an error (e.g., failed login or signup), an alert box displays the message:{error && ( <div className="bg-red-500/10 border-2 ... rounded-lg p-4 mb-6"> <p className="text-red-300 text-sm">{error}</p> </div> )}
-
Conditional Rendering:
The component avoids premature form rendering if the user is already authenticated (returnsnull).
The AuthPage component is structured to:
- Immediately check authentication and redirect if needed.
- Provide a clear UI for choosing an authentication provider.
- Support toggling between login and signup.
- Handle both traditional email/password authentication and OAuth through Google and GitHub.
- Manage loading and error states to provide immediate user feedback.
- Include a secure password reset workflow via a modal component.
This design ensures a smooth and user-friendly authentication experience within the application.
The ForgotPassword component is a modal that handles password reset functionality. It provides a simple interface for users to request a password reset link via email.
- Modal interface with backdrop
- Email validation
- Loading states
- Success/Error feedback
- Cancel functionality
const [email, setEmail] = useState('');
const [success, setSuccess] = useState(false);
const { loading, error } = useSelector(state => state.auth);- User enters email
- Form submission triggers
resetPasswordaction - Success message shown on completion
- Error displayed if request fails
const handleSubmit = async (e) => {
e.preventDefault();
try {
await dispatch(resetPassword(email));
setSuccess(true);
} catch (err) {
// Error handled by reducer
}
};- Initial Form
<form onSubmit={handleSubmit} className="space-y-4">
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
<button type="submit" disabled={loading}>
{loading ? 'Sending...' : 'Send Reset Link'}
</button>
</form>- Success State
{success && (
<div className="text-green-400">
Check your email for password reset instructions.
</div>
)}- Error State
{error && (
<div className="text-red-400">{error}</div>
)}- Opens when parent sets
showForgotPasswordto true - Closes via
onCloseprop callback
<button onClick={onClose} className="...">
Cancel
</button>- User clicks "Forgot Password?" β Modal opens
- User enters email β Submits form
- System sends reset link β Shows success message
- User clicks "Cancel" or completes flow β Modal closes