Skip to content

Commit aa32cd4

Browse files
Feat/NaverLogin #7 네이버로그인 변경된 URI적용
1 parent 2a7628c commit aa32cd4

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/components/login/NaverLogin.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import NaverUnion from "../../img/NaverUnion.png";
44
const NaverLogin = () => {
55
const naverRef = useRef();
66
const { naver } = window;
7-
// 깃헙에 올릴 땐 아래의 env활용
7+
88
const NAVER_CLIENT_ID = "T9R5hFNUTuTa1UqoVBcO";
99
// process.env.REACT_APP_NAVER_CLIENT_ID;
10-
const NAVER_CALLBACK_URL = "http://localhost:3000/callback";
10+
const NAVER_CALLBACK_URL = "http://localhost:3000/social/naver-login";
1111
// process.env.REACT_APP_NAVER_CALLBACK_URL;
1212
const initializeNaverLogin = () => {
1313
const naverLogin = new naver.LoginWithNaverId({

src/components/login/NaverLoginLoding.jsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ function NaverLoginLoding() {
99
const getToken = async () => {
1010
const navertoken = window.location.href.split("=")[1].split("&")[0];
1111
console.log(navertoken);
12-
// URL에서 추출한 access token을 로컬 스토리지에 저장
1312

1413
// sessionStorage.setItem("NaverAuthorization", navertoken);
1514
};
1615

1716
const sendTokenAndGetAuthorization = async () => {
1817
await axios
19-
.post("https://eb.jxxhxxx.shop/naver/login", {
20-
// .post("http://hayangaeul.shop/naver/login", {
21-
token: window.location.href.split("=")[1].split("&")[0],
22-
})
18+
.post(
19+
"https://eb.jxxhxxx.shop/social/naver-login",
20+
21+
{ token: window.location.href.split("=")[1].split("&")[0] }
22+
)
2323

2424
.then((res) => {
2525
//이미 멤버라면 Authorization이 담겨 올 것이고, member라고
@@ -33,10 +33,11 @@ function NaverLoginLoding() {
3333
const userId = res.data.data.userId;
3434
const profileImage = res.data.data.profileImage;
3535
console.log(nickname);
36-
sessionStorage.setItem("token", accessToken);
36+
sessionStorage.setItem("accessToken", accessToken);
3737
sessionStorage.setItem("nickname", nickname);
3838
sessionStorage.setItem("profileImage", profileImage);
3939
sessionStorage.setItem("userId", userId);
40+
sessionStorage.setItem("email", email);
4041
alert("그님스에 오신걸 환영합니다");
4142
return window.location.assign("/main");
4243

src/components/main/Main.jsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,28 @@ import { __getSchedule } from "../../redux/modules/ScheduleSlice";
1010
const Main = () => {
1111
const navigate = useNavigate();
1212
const [profileImg, setProfileImg] = useState(defaultprofileImg);
13-
const [nickName, setNickname] = useState("");
13+
const [nickName, setNickname] = useState(sessionStorage.getItem("nickname"));
1414
const [email, setEmail] = useState("");
1515
const dispatch = useDispatch();
1616
const { schedules } = useSelector((state) => state.ScheduleSlice);
1717
const { isLoding } = useSelector((state) => state.ScheduleSlice);
1818
console.log(schedules);
1919

2020
useEffect(() => {
21-
const userId = window.sessionStorage.getItem("userId");
22-
const getnickName = window.sessionStorage.getItem("nickname");
23-
const getprofilImg = window.sessionStorage.getItem("profileImage");
24-
const getEmail = window.sessionStorage.getItem("email");
25-
if (getnickName && getEmail) {
26-
setNickname(() => getnickName);
27-
setEmail(() => getEmail);
21+
const getNickname = sessionStorage.getItem("nickname");
22+
const getemail = sessionStorage.getItem("email");
23+
const getprofilImg = sessionStorage.getItem("profileImage");
24+
const userId = sessionStorage.getItem("userId");
25+
26+
if (getNickname && getemail) {
2827
if (getprofilImg) {
2928
setProfileImg(getprofilImg);
3029
}
31-
dispatch(__getSchedule(userId));
3230
} else {
3331
navigate(`/login`);
3432
}
35-
}, [navigate, dispatch]);
36-
sessionStorage.removeItem("selectedJoiner");
37-
sessionStorage.removeItem("selectedJoinerNames");
33+
dispatch(__getSchedule(userId));
34+
}, [navigate, nickName, dispatch]);
3835

3936
return (
4037
<>

src/shared/Router.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const Router = () => {
5757
<Route path="/kakaoLogin" element={<KakaoLogin />} />
5858
<Route path="auth/kakao/callback" element={<KakaoLoginLoding />} />
5959
<Route path="/naver/login" element={<NaverLoginPage />} />
60-
<Route path="/auth/naver/callback" element={<NaverLoginLoding />} />
60+
<Route path="/social/naver-login" element={<NaverLoginLoding />} />
6161

6262
{/* 마이페이지 */}
6363
<Route path="/profile" element={<Profile />} />

0 commit comments

Comments
 (0)