Skip to content

Manage bearer token in api calls #172

Answered by yjose
quentinfon asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @quentinfon, as we are using Axios for API calls, you can easily use interceptors to add authorization headers, as well as to refresh tokens.
Here is a complete example on how to do it

// api/client.ts
import {Env} from '@env';
import type {AxiosRequestConfig} from 'axios';
import axios from 'axios';
import createAuthRefreshInterceptor from 'axios-auth-refresh';

import {refreshAuthLogic} from './refresh-auth-logic';

export const client = axios.create({
  baseURL: Env.API_URL,
});

//Once you have logged in and received the token, you should set the token using this function
export const setHeaderToken = (token: string) => {
  if (token) {
  client.defaults.headers.common.Authorization 

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by quentinfon
Comment options

You must be logged in to vote
0 replies
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