Commit b81df368 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

kakaologin

parent 90b3d3d6
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { authApi } from "../apis"; import { authApi } from "../apis";
import { catchErrors } from "../helpers";
const LOCAL_USER_INFO = "survey-user-info";
export const OAuthRedirectHandler = () => { export const OAuthRedirectHandler = () => {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState( const [message, setMessage] = useState(
"잠시만 기다려 주세요! 로그인 중입니다." "잠시만 기다려 주세요! 로그인 중입니다."
); );
...@@ -12,13 +17,26 @@ export const OAuthRedirectHandler = () => { ...@@ -12,13 +17,26 @@ export const OAuthRedirectHandler = () => {
}, []); }, []);
useEffect(() => { useEffect(() => {
const getKakaoUserData = async (code: string) => { const kakaoLogin = async (code: string) => {
const userData = await authApi.getKakaoUserData(code); try {
console.log(userData); const user = await authApi.getKakaoUserData(code);
console.log(user);
if (user) {
localStorage.setItem(
LOCAL_USER_INFO,
JSON.stringify({
isLoggedIn: user.isLoggedIn,
})
);
}
} catch (error) {
setLoading(false);
catchErrors(error, setError);
}
}; };
if (code) { if (code) {
console.log("code=", code); console.log("code=", code);
getKakaoUserData(code); kakaoLogin(code);
} }
}, [code]); }, [code]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment