-
Notifications
You must be signed in to change notification settings - Fork 1
bugfix: #105 소셜로그인 이후 토큰이 있어도 401로 떨어지는 현상해결 #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,30 @@ | ||
| import { loginState } from "@/store/user"; | ||
| import { ACCESS_TOKEN } from "@/utils/constant"; | ||
| import { useSetAtom } from "jotai"; | ||
| import { useEffect } from "react"; | ||
| import { useLocation, useNavigate } from "react-router-dom"; | ||
| import { useNavigate } from "react-router-dom"; | ||
| import { useSetAtom } from "jotai"; | ||
| import { loginState, tokenState } from "@/store/user"; | ||
| import { ACCESS_TOKEN } from "@/utils/constant"; | ||
|
|
||
| export default function Oauth2Redirect() { | ||
| const location = useLocation(); | ||
| const navigate = useNavigate(); | ||
| const params = new URLSearchParams(location.search); | ||
| const accessToken = params.get("accessToken"); | ||
| const setLogin = useSetAtom(loginState); | ||
| const setToken = useSetAtom(tokenState); | ||
|
|
||
| useEffect(() => { | ||
| if (accessToken) { | ||
| localStorage.setItem(ACCESS_TOKEN, accessToken); | ||
| const params = new URLSearchParams(window.location.search); | ||
| const token = params.get("token"); | ||
|
|
||
| if (token) { | ||
| localStorage.setItem(ACCESS_TOKEN, token); | ||
| setToken(token); | ||
|
Comment on lines
+17
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainCritical: Token key inconsistency between localStorage and atom state. There's a mismatch in token storage keys:
This inconsistency will cause synchronization issues between localStorage and the atom state. To fix this, either:
- localStorage.setItem(ACCESS_TOKEN, token);
- setToken(token);
+ setToken(token); // atomWithStorage will handle localStorage automatically🏁 Script executed: #!/bin/bash
# Verify the ACCESS_TOKEN constant value and usage across the codebase
echo "Checking ACCESS_TOKEN constant definition:"
rg "ACCESS_TOKEN.*=" --type ts
echo -e "\nChecking ACCESS_TOKEN usage:"
rg "ACCESS_TOKEN" --type ts -A 2 -B 2Length of output: 3738 🏁 Script executed: #!/bin/bash
# Search for tokenState definition in the codebase
rg "tokenState" -n --type ts
# Show the file containing tokenState to inspect its definition
rg -A5 "tokenState" --type tsLength of output: 1207 Ensure consistent token storage key across localStorage and atom state The
To resolve, pick one shared key and apply it everywhere: • src/utils/constant.ts - const ACCESS_TOKEN = btoa("FLOWBIT_ACT");
+ export const ACCESS_TOKEN = "accessToken";• src/store/user/index.ts - export const tokenState = atomWithStorage("accessToken", "");
+ export const tokenState = atomWithStorage(ACCESS_TOKEN, "");• src/app/oauth2/redirect/index.tsx - localStorage.setItem(ACCESS_TOKEN, token);
- setToken(token);
+ setToken(token); // atomWithStorage will now handle both state and localStorage under ACCESS_TOKENOr, if you prefer to keep the base64 key, swap the 🤖 Prompt for AI Agents |
||
| setLogin(true); | ||
| navigate("/"); | ||
| } else { | ||
| alert("오류가 발생했어요, 관리자에게 문의해주세요"); | ||
| // 토큰이 없는 경우 에러 처리 | ||
| setLogin(false); | ||
| setToken(""); | ||
| navigate("/signin"); | ||
| } | ||
| }, []); | ||
| }, [navigate, setLogin, setToken]); | ||
|
|
||
| return <>처리중입니다.</>; | ||
| return null; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { atomWithStorage } from "jotai/utils"; | ||
|
|
||
| export const loginState = atomWithStorage("isLogin", false); | ||
| export const loginState = atomWithStorage("isLogin", false); | ||
| export const tokenState = atomWithStorage("accessToken", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove duplicate Authorization header logic.
The Authorization header is being set twice:
The static header setting at instance creation won't update when the token changes, making it unreliable. The request interceptor already handles this correctly by reading the fresh token on each request.
📝 Committable suggestion
🤖 Prompt for AI Agents