Authentication

Auth0, JWT, Firebase setup

Mantis includes four authentication methods JSON Web Token (JWT), Firebase, Auth0, AWS and Supabasefor its users. Users can change it as per their needs.

How does it work?

Only authenticated users can access dashboard pages. If a user is not authenticated, the user is redirected to the login page.

We used two guards GuestGuard and AuthGuard. Guards have been configured in src\utils\route-guard\ folder.

In the src/layout/App.tsx, we have specified auth provider JWTProvider like,

src/App.tsx
import { JWTProvider as AuthProvider } from 'contexts/JWTContext';

App component wraps with the <JWTProvider>

src/App.tsx
<ThemeCustomization>
  ...
  <AuthProvider>
    <Routes />
    <Snackbar />
  </AuthProvider>
  ...
</ThemeCustomization>

Using <JWTProvider>, we can use the context directly by importing useContext from React and specifying the context JWTContext or we can use the custom hook useAuth from src/hooks/useAuth.js

Auth Configuration:

All configurations related to authentication are stored in config.ts. Those configs are like APIKey to connect the authentication server, project ID, etc.

.env
## Firebase - Google Auth 
VITE_APP_FIREBASE_API_KEY=
VITE_APP_FIREBASE_AUTH_DOMAIN=
VITE_APP_FIREBASE_PROJECT_ID=
VITE_APP_FIREBASE_STORAGE_BUCKET=
VITE_APP_FIREBASE_MESSAGING_SENDER_ID=
VITE_APP_FIREBASE_APP_ID=
VITE_APP_FIREBASE_MEASUREMENT_ID=

## AWS
VITE_APP_AWS_POOL_ID=
VITE_APP_AWS_APP_CLIENT_ID=

## Auth0
VITE_APP_AUTH0_CLIENT_ID=
VITE_APP_AUTH0_DOMAIN=

## SupaBase
VITE_SUPABASE_URL=
VITE_SUPABASE_ANON_KEY=

The theme provides working an example for Login and Register only. Other flow like reset password, verification have to make it workable by the user himself.

Switching between Authentication methods