Frontend - Fetch Token

Obtaining the JWT from the frontend

1. Import the user object

import { useUser } from "0xpass";

2. Extract getAccessToken method from useUser()

In order to be able to use the JWT, we must extract it out of the useUser() hook as shown below. Please note this should in the components that is within the <PassProvider> component.

const { getAccessToken} = useUser();

3. Make an async call

const accessToken = await getAccessToken()

4. Share it with backend

For example, on a fetch request, you might include the user's auth token as follows:

const response = await fetch("http://localhost:3000/api", {
  headers: {
    Authorization: `Bearer ${accessToken}`,