> For the complete documentation index, see [llms.txt](https://codedthemes.gitbook.io/berry/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codedthemes.gitbook.io/berry/v1.2.0/authentication.md).

# Authentication

Berry supports three Authentication methods  **`Firebase, JSON Web Token (JWT), Auth0.`**

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

## 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 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 } from "../contexts/FirebaseContext";
```

{% endcode %}

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

```javascript
<ThemeProvider theme={theme(customization)}>
  <FirebaseProvider>
    <Routes />
    <Snackbar />
  </FirebaseProvider>
</ThemeProvider>
```

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:

{% hint style="info" %}
You can edit this file at **`[ ../src/config.js]`**
{% endhint %}

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

```javascript
// JWT JSON Web Token method
jwt: {
    secret: 'SECRET-KEY',
    timeout: '1 days'
},

// Firebase Authentication method
firebase: {
    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
auth0: {
    client_id: 'CLIENT-ID',
    domain: 'DOMAIN'
}
```

{% endcode %}

## Switching between Authentication methods

### **Firebase to JWT**

**Set JWT Config**

Open file **`config.js`** from directory **`..\src\config.js`** and set **`jwt`**  configuration.

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

```javascript
...
  jwt: {
      secret: 'SECRET-KEY',
      timeout: '1 days'
  }
...
```

{% endcode %}

**Change Login Form**

Open file **`index.js`**  at directory **`..\src\views\pages\authentication\login\index.js`** and use the **`JWTLogin`** component.

{% code title="login\index.js" %}

```javascript
// Replace at line 8:
import JWTLogin from './JWTLogin';


// Also find & edit below code block
<Grid item xs={12}>
    <JWTLogin />
    {/* <Auth0Login /> */}
    {/* <FirebaseLogin /> */}
</Grid>
```

{% endcode %}

**Change AuthProvider**

Open file **`App.js`** at directory **`..\src\App.js`** and use **`JWTProvider`**

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

```javascript
// Replace at line 6:
import { JWTProvider } from "./contexts/JWTContext";

// Also find & edit below code block
<JWTProvider>
    <Routes />
    <Snackbar />
</JWTProvider>
```

{% endcode %}

**Change auth Hooks**

Open file **`useAuth.js`** at directory `..\src\hooks\useAuth.js` and use **`JWTContext`**

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

```javascript
// Replace from line 2:
import JWTContext from '../contexts/JWTContext';
const useAuth = () => useContext(JWTContext);
```

{% endcode %}

### **Firebase to Auth0**

**Set Auth0 Config**

Open file **`config.js`** from directory **`..\src\config.js`** and set **`jwt`**  configuration.

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

```javascript
...
  auth0: {
      client_id: 'client_id',
      domain: 'yourdomain.com'
  }
...
```

{% endcode %}

**Change Login Form**

Open file **`index.js`**  at directory **`..\src\views\pages\authentication\login\index.js`** and use the **`Auth0Login`** component.

{% code title="\login\index.js" %}

```javascript
// Replace at line 8:
import Auth0Login from './Auth0Login';


// Also find & edit below code block
<Grid item xs={12}>
    {/* <JWTLogin /> */}
    <Auth0Login />
    {/* <FirebaseLogin /> */}
</Grid>
```

{% endcode %}

**Change AuthProvider**

Open file **`App.js`** at directory **`..\src\App.js`** and use **`Auth0Provider`**

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

```javascript
// Replace at line 6:
import {Auth0Provider} from "./contexts/Auth0Context";

// Also find & edit below code block
<Auth0Provider>
    <Routes />
    <Snackbar />
</Auth0Provider>
```

{% endcode %}

**Change auth Hooks**

Open file **`useAuth.js`** at directory **`..\src\hooks\useAuth.js`** and use **`Auth0Context`**

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

```javascript
// Replace from line 2:
import Auth0Context from '../contexts/Auth0Context';
const useAuth = () => useContext(Auth0Context);
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://codedthemes.gitbook.io/berry/v1.2.0/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
