# Authentication

Mantis includes four Authentication methods **`Firebase, JSON Web Token (JWT), Auth0, AWS`** for its users. Users can change it as per their needs.

{% hint style="info" %}
Firebase Authentication is set by default
{% endhint %}

## 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.js`**, we have specified auth provider **`FirebaseProvider`** like,

{% code title="App.js" %}

```javascript
import { FirebaseProvider as AuthProvider } from 'contexts/FirebaseContext';
```

{% endcode %}

App component wrap with the **`<FirebaseProvider>`**

```javascript
<ThemeCustomization>
  ...
  <AuthProvider>
    <Routes />
    <Snackbar />
  </AuthProvider>
  ...
</<ThemeCustomization>>
```

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

## Auth Configuration:

All configurations related to authentication are stored in config.js. Those configs are like APIKey to connect authentication server, project id, etc.

{% hint style="danger" %}
Mantis has a dummy/test config to make authentication work. Users have to change API and secret as per their project needs. One must not use those provided keys in their live environment.
{% endhint %}

{% code title="config.js" %}

```javascript
// JWT JSON Web Token method
export const JWT_API = {
    secret: 'SECRET-KEY',
    timeout: '1 days'
};

// Firebase Authentication method
export const FIREBASE_API = {
    apiKey: "API-KEY",
    authDomain: "AUTH-DOMAIN",
    databaseURL: "DATABASE-URL",
    projectId: "PROJECT-ID",
    storageBucket: "STORAGE-BUCKET",
    messagingSenderId: "MESSAGEING-SENDER-ID",
    appId: "APP-ID",
    measurementId: "MEASUREMENT-ID"
};

// Auth0 method
export const AUTH0_API = {
    client_id: 'CLIENT-ID',
    domain: 'DOMAIN'
};

// AWS method
export const AWS_API = {
    poolId: 'poolid',
    appClientId: 'appid'
};
```

{% endcode %}

> 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

### [**Firebase to Auth0**](https://codedthemes.gitbook.io/mantis/v1.2.0/authentication/switch-to-auth0)

### [**Firebase to** JWT](https://codedthemes.gitbook.io/mantis/v1.2.0/authentication/switch-to-jwt)

### [**Firebase to AWS Cognito**](https://codedthemes.gitbook.io/mantis/v1.2.0/authentication/switch-to-aws-cognito)
