# Authentication

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

{% hint style="info" %}
JWT 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 **`JWTProvider`** like,

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

```javascript
import { JWTProvider as AuthProvider } from 'contexts/JWTContext';
```

{% endcode %}

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

```javascript
<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.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=".env" %}

```javascript
## Firebase - Google Auth 
REACT_APP_FIREBASE_API_KEY=
REACT_APP_FIREBASE_AUTH_DOMAIN=
REACT_APP_FIREBASE_PROJECT_ID=
REACT_APP_FIREBASE_STORAGE_BUCKET=
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=
REACT_APP_FIREBASE_APP_ID=
REACT_APP_FIREBASE_MEASUREMENT_ID=

## AWS
REACT_APP_AWS_POOL_ID=
REACT_APP_AWS_APP_CLIENT_ID=

## JWT
REACT_APP_JWT_SECRET_KEY=ikRgjkhi15HJiU78-OLKfjngiu=
REACT_APP_JWT_TIMEOUT=1d

## Auth0
REACT_APP_AUTH0_CLIENT_ID=
REACT_APP_AUTH0_DOMAIN=enve
```

{% 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

### [**JWT to Auth0**](/mantis/v2.1.0/authentication/switch-to-auth0.md)

### [**JWT to Firebase** JWT](/mantis/v2.1.0/authentication/switch-to-firebase.md)

### [**JWT to AWS Cognito**](/mantis/v2.1.0/authentication/switch-to-aws-cognito.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codedthemes.gitbook.io/mantis/v2.1.0/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
