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

kakaologin

parent 90b3d3d6
import React, { useEffect, useState } from "react";
import { authApi } from "../apis";
import { catchErrors } from "../helpers";
const LOCAL_USER_INFO = "survey-user-info";
export const OAuthRedirectHandler = () => {
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [message, setMessage] = useState(
"잠시만 기다려 주세요! 로그인 중입니다."
);
......@@ -12,13 +17,26 @@ export const OAuthRedirectHandler = () => {
}, []);
useEffect(() => {
const getKakaoUserData = async (code: string) => {
const userData = await authApi.getKakaoUserData(code);
console.log(userData);
const kakaoLogin = async (code: string) => {
try {
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) {
console.log("code=", code);
getKakaoUserData(code);
kakaoLogin(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