Skip to content

Commit

Permalink
fix: Auth Initial Header
Browse files Browse the repository at this point in the history
  • Loading branch information
joohaem committed Jun 21, 2023
1 parent c25ed24 commit c73bd66
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/atom/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const userTokenAtom = atom<string | null>({
key: StateType.USER_TOKEN_ATOM,
default: localStorage.getItem(USER_TOKEN) || null,
effects: [
() => {
const initialToken = localStorage.getItem(USER_TOKEN);
if (initialToken) axiosInstance.defaults.headers.common["x-auth-token"] = `Bearer ${initialToken}`;
},
({ onSet }) => {
onSet((newToken, _, isReset) => {
if (isReset || newToken === null) {
Expand Down

0 comments on commit c73bd66

Please sign in to comment.