> 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/v3.9.0/authentication.md).

# Authentication

Berry offers four authentication methods - JSON Web Token (JWT), Firebase, Auth0 and AWS - for users to choose from and can be changed to match the user's needs.

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

## How does it work?

Access to dashboard pages is restricted to authenticated users. If a user is not authenticated, they will be 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`

## For Remix

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

In the **`app/root.tsx`**, we have specified auth provider **`JWTProvider`** like,

{% code title="root.tsx" %}

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

{% endcode %}

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

```typescript
<ThemeCustomization>
  ...
  <AuthProvider>
    <Outlet />
    <Snackbar />
  </AuthProvider>
  ...
</ThemeCustomization>
```

## Auth Configuration:

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

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

{% code title=".env" %}

```javascript
VITE_APP_VERSION=v3.9.1
GENERATE_SOURCEMAP=false

## Bakeend API URL
VITE_APP_API_URL=https://mock-data-api-nextjs.vercel.app/
VITE_APP_BASE_NAME=

## Map Box 
VITE_APP_MAPBOX_ACCESS_TOKEN=

## 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=

```

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


---

# 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/v3.9.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.
