# 8base web auth0 auth client

The 8base auth0 auth client for the `AuthProvider`.

## WebAuth0AuthClient

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [WebAuth0AuthClient](#webauth0authclient)
    -   [Parameters](#parameters)

### WebAuth0AuthClient

Create an instance of the web auth0 auth client.

#### Parameters

-   `workspaceId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Identifier of the 8base app workspace.
-   `domain` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Domain. See auth0 documentation.
-   `clientId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Client id. See auth0 documentation.
-   `redirectUri` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Redurect uri. See auth0 documentation.

## Usage

### Without authentication profile
```js
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/react-auth';
import { WebAuth0AuthClient } from '@8base/web-auth0-auth-client';

  const authClient = new WebAuth0AuthClient({
    domain: 'domain',
    clientId: 'client-id',
    redirectUri: `${window.location.origin}/auth/callback`,
    logoutRedirectUri: `${window.location.origin}/auth`,
  });

  const renderAuth = (auth) => {
    const authorize = async () => {
      const authData = await auth.authorize();

      await auth.setAuthState({
        token: authData.idToken,
        email: authData.email,
      });
    };

    const logout = async () => {
      await auth.purgeState();
      await auth.logout();
    };

    if (auth.isAuthorized) {
      return (
        <div>
          <p>Hi ${auth.authState.email} !</p>
          <button type='button' onClick={ logout }>Logout</button>
        </div>
      );
    }

    return (
      <div>
        <button type='button' onClick={ authorize }>Authorize with auth0<button/>
      </div>
    );
  };

  ...

  <AuthProvider authClient={ authClient }>
    ...
      <AuthContext.Consumer>
        { renderAuth }
      </AuthContext.Consumer>
    ...  
  </AuthProvider>
```

### With custom authentication profile
```js

...

import { WebAuth0AuthClient } from '@8base/web-auth0-auth-client';

  const authClient = new WebAuth0AuthClient({
    domain: 'domain',
    clientId: 'client-id',
    redirectUri: `${window.location.origin}/auth/callback`,
    logoutRedirectUri: `${window.location.origin}/auth`,
    workspaceId: 'workspace-id',
    profile: {
      id: 'profile-id',
    },
  });

...

```

### With default authentication profile
```js

...

import { WebAuth0AuthClient } from '@8base/web-auth0-auth-client';

  const authClient = new WebAuth0AuthClient({
    domain: 'domain',
    clientId: 'client-id',
    redirectUri: `${window.location.origin}/auth/callback`,
    logoutRedirectUri: `${window.location.origin}/auth`,
    workspaceId: 'workspace-id',
    profile: {
      id: 'profile-id',
      isDefault: true,
    },
  });

...

```
