axios create authoriztion

김듑듑·2022년 12월 7일
0

프론트엔드

목록 보기
23/24

삽질

const instance = axios.create({
  ...baseSettings,
  headers: {
    Authorization: `Bearer 어쩌고`,
  },
  withCredentials: false,
});
instance.defaults.headers.common.Authorization = `Bearer 어쩌고`;

는 다름
전자는 header > Auth를 만드는거
후자는 header > common > Auth 만드는거

전자랑 같게하려면
후자를 쓰면 안되고

import { HeadersDefaults } from 'axios';

interface CommonHeaderProperties extends HeadersDefaults {
  Authorization: string;
}

instance.defaults.headers = {
	Authorization: `Bearer ${token}`,
    } as CommonHeaderProperties;

0개의 댓글