-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
089a85d
commit 1bd977b
Showing
8 changed files
with
197 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
// eslint-disable-next-line | ||
|
||
import React, { useEffect } from "react"; | ||
import { useNavigate, useLocation } from "react-router-dom"; | ||
import axios from "axios"; | ||
import { useNavigate } from "react-router-dom"; | ||
// import axios from "axios"; | ||
import { useDispatch } from "react-redux"; | ||
import { CircularProgress } from "@mui/material"; | ||
import styled from "styled-components"; | ||
import { __kakaoLogin } from "../../redux/modules/memberSlice.js"; | ||
|
||
const KakaoLogin = () => { | ||
const memberApi = process.env.REACT_APP_MEMBER; | ||
const navigate = useNavigate(); | ||
const dispatch = useDispatch(); | ||
|
||
// 카카오버튼 클릭시 생겨난 url를 잡아온다 | ||
const location = useLocation(); | ||
const code = new URL(window.location.href).searchParams.get("code"); | ||
|
||
// url 1번재 "=" 뒤에 있는 인가코드를 잡아온다 | ||
const kakaoCode = location.search.split("=")[1]; | ||
|
||
const postCode = async () => { | ||
try { | ||
const response = await axios.get( | ||
memberApi + `/member/login?code=${kakaoCode}`, | ||
{ | ||
// 백엔드 보내기. | ||
} | ||
); | ||
localStorage.setItem("userToken", response.headers.authorization); | ||
localStorage.setItem("email", response.data.output.email); | ||
localStorage.setItem("phone", response.data.output.tel); | ||
localStorage.setItem("name", response.data.output.name); | ||
localStorage.setItem("refreshToken", response.headers.refreshtoken); | ||
// console.log(response); | ||
navigate("/"); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
useEffect(() => { | ||
postCode(); | ||
}, []); | ||
return <div></div>; | ||
dispatch(__kakaoLogin(code)); | ||
// postCode(); | ||
navigate("/"); | ||
}, [dispatch]); | ||
|
||
return ( | ||
<KakaoLoadingContainer> | ||
<CircularProgress /> | ||
</KakaoLoadingContainer> | ||
); | ||
}; | ||
|
||
const KakaoLoadingContainer = styled.div` | ||
display: block; | ||
margin: 18% auto; | ||
text-align: center; | ||
`; | ||
|
||
export default KakaoLogin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.