Authentication
Gradient able react hooks supports 3 popular authentication methods.
Gradient Able React Hooks supports 3 authentication methods: Firebase Authentication, JSON Web Token, Auth0. We provide Firebase Authentication by default.
How does it work?
Only authenticated users can access dashboard pages. If a user is not authenticated, the user redirected to the login page.
We implemented to make this work the “Guard” concept from Angular. It is simply a component that wraps a route and checks for user authentication status before allowing the navigation.
We used two guards GuestGuard and AuthGuard, To find more information about guards, please visit the Routes.js page.
In the src/App.jsx
, we have specified auth provider JWTProvider like,
App component wrap with the provider, like
Using FirebaseProvider, we can use the context directly by importing useContext
from React and specifying the context FirebaseContext that we want to use or we can use the custom hook useAuth
from src/hooks/useAuth.jsx
Auth Configuration:
You can edit this file at [ ../.env]
Switching between Authentication methods
JWT to Firebase
Set JWT Config - Open file '.env' at directory '../env' and set firebase configuration.
Change Login Form - Open file 'SignIn1.jsx' at directory 'src/views/auth/signin/SignIn1.jsx', and use the FirebaseLogin component.
AuthProvider for Layout - Open file 'App.jsx' at directory 'src/App.jsx' and use FirebaseProvider
Change auth Hooks - Open file 'useAuth.jsx' at directory '../src/hooks/useAuth.jsx' and use FirebaseContext
Firebase to Auth0
Set Auth Config - Open file '.env' at directory '.env' and set auth0 configuration.
Change Login Form - Open file 'SignIn1.jsx' at directory 'src/views/auth/signin/SignIn1.jsx', and use Auth0Login component.
AuthProvider for Layout - Open file 'App.jsx' at directory 'src/App.jsx' and use Auth0Provider
Change auth Hooks - Open file 'useAuth.jsx' at directory 'src/hooks/useAuth.jsx' and use Auth0Context
Last updated