<!-- Source: https://www.wappi.dev/frontend-integration/authentication -->

# Authentication

Wappi-fe provides built-in authentication handling to seamlessly manage user sessions and secure API calls.

## How Authentication Works

To generate authentication with wappi, you need to add code to your wappi server endpoint called **Core_Login_1_0_0** or any subsequent versions.
When this endpoint is called, wappi-fe will set a auth token to localStorage of the browser / device called: wappiAuthToken.
This Auth Token will be used as an encrypted authentication between your frontend and backend.
If the token is expired, or incorrect. Then endpoint will return:

```typescript
success: false
```

## Using Authentication in the Request

When calling request. You only need to pass in the flag

#### authRequired:

boolean

optionally required - depends on query type

If true, it will get the auth token that is automatically set.
See the Authentication section.

```typescript
const response = async () => (request(WAPPI_CONFIG, {
  name: 'Request',
  query: 'NameSpace_FunctionName_1_0_0',
  data: {
    // ... body object specific to the query endpoint type
  },
  authRequired: true,
}))
```

If an endpoint doesn't require auth, then don't include it.

```typescript
const response = async () => (request(WAPPI_CONFIG, {
  name: 'Request',
  query: 'NameSpace_FunctionName_1_0_0',
  data: {
    // ... body object specific to the query endpoint type
  },
}))
```

URL: https://www.wappi.dev/frontend-integration/authentication
