How do you access the access_token in the frontend? #92
-
The issueI have a FastAPI endpoint set up like in the tutorial:
and I want to call it from my frontend. To do this, I need to call the endpoint with a dictionary that includes an access_token. I can login to Fief in my frontend. How do I extract the access_token of the current user so I can pass it to the backend? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
It depends on how you obtained the access token in your frontend. If you followed the browser example, the token is available through the Then, you can pass it in the 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.json() |
Beta Was this translation helpful? Give feedback.
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 aFiefTokenResponse
object containing the access token.Then, you can pass it in the
Authorization
header when making API requests to your backend.