fix: 로그인 기능 fix

This commit is contained in:
jhynsoo 2024-07-26 15:05:05 +09:00
parent 8aa0a15413
commit 2b075e9d31
2 changed files with 9 additions and 6 deletions

View File

@ -11,10 +11,13 @@ export function useAuth() {
userId,
password,
};
return instance
.post(`${API_URL}/user/login`, formData)
.then(({ data }) => data['access-token'])
.then((accessToken) => {
.then(({ data, config }) => {
const { 'access-token': accessToken } = data;
config.headers.Authorization = `${accessToken}`;
setToken(accessToken);
// TODO: userType 구분 추가
setUserType('student');

View File

@ -12,10 +12,10 @@ const instance = axios.create({
});
instance.interceptors.request.use((config) => {
const accessToken = useBoundStore.getState().accessToken;
const accessToken = useBoundStore.getState().token;
if (accessToken) {
config.headers.Authorization = `Bearer ${accessToken}`;
config.headers.Authorization = `${accessToken}`;
}
return config;
@ -34,8 +34,8 @@ instance.interceptors.response.use(
return instance.post(REFRESH_API_URL).then((response) => {
const { accessToken } = response.data;
useBoundStore.setState({ accessToken });
error.config.headers.Authorization = `Bearer ${accessToken}`;
useBoundStore.setState({ token: accessToken });
error.config.headers.Authorization = `${accessToken}`;
return instance(error.config);
});
}