Skip to content

How do you access the access_token in the frontend? #92

Answered by frankie567
gooseman1721 asked this question in Q&A
Discussion options

You must be logged in to vote

It depends on how you obtained the access token in your frontend. If you followed the browser example, the token is available through the fiefAuth.getTokenInfo method. It'll return you a FiefTokenResponse object containing the access token.

Then, you can pass it in the Authorization header when making API requests to your backend.

const tokenResponse = fiefAuth.getTokenInfo();
const accessToken = tokenResponse.access_token;
// Make a request with fetch; but it can be axios or whatever you like to make XHR requests
const response = await fetch(
    'http://localhost:8000/fief/user',
    {
        headers: {
            Authorization: `Bearer ${accessToken}`,
        }
    }
);
data = response

Replies: 1 comment 10 replies

Comment options

You must be logged in to vote
10 replies
@frankie567
Comment options

@gooseman1721
Comment options

@gooseman1721
Comment options

@frankie567
Comment options

@gooseman1721
Comment options

Answer selected by gooseman1721
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants