This repository contains an implementation of a Firebase Authentication Provider for a React application using the Refine framework.
- User login with email and password
- User registration with email, password, and display name
- Password reset functionality
- Persistent login sessions
- User profile updates
- Email verification after registration
-
Install the dependencies:
npm i @kenny9/refine-firebase
-
Set up your Firebase project:
- Go to the Firebase Console.
- Create a new project or use an existing one.
- Go to the Project Settings and add a new web app.
- Copy the Firebase configuration and replace the placeholder in
firebaseConfig.ts
.
-
Configure Firebase Authentication:
- Enable Email/Password authentication in the Firebase Console under Authentication > Sign-in method.
-
Import the
FirebaseAuth
class and set up your authentication provider:import { FirebaseAuth } from "./firebaseauth"; import { authProvider } from "./authProvider"; const firebaseAuth = new FirebaseAuth(); const authProvider = firebaseAuth.getAuthProvider();
-
Use the authentication provider in your application:
import { Refine } from "@refinedev/core"; import { authProvider } from "./authProvider"; function App() { return ( <Refine authProvider={authProvider}> {/* Your app components */} </Refine> ); }
The FirebaseAuth
class provides methods to handle various authentication tasks:
-
handleLogIn
: Logs in a user with email and password. -
handleRegister
: Registers a new user with email, password, and optional display name. -
handleLogOut
: Logs out the current user. -
handleResetPassword
: Sends a password reset email. -
handleUpdatePassword
: Updates the current user's password. -
handleForgotPassword
: Sends a password reset email. -
getUserIdentity
: Returns the current user's email and display name. -
handleCheckAuth
: Checks if a user is authenticated. -
getPermissions
: Returns the user's permissions.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.