From 7f34bdaa9356fd5fa03d7ae7dec2df35cbd01128 Mon Sep 17 00:00:00 2001 From: ohwoo-kwon Date: Wed, 1 Jun 2022 22:21:51 +0900 Subject: [PATCH 1/2] Feat: get token from kakao server --- urmine-frontend/src/Routes/Pokedex.tsx | 21 +++++++++++++++++++++ urmine-frontend/src/api/user.ts | 13 +++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/urmine-frontend/src/Routes/Pokedex.tsx b/urmine-frontend/src/Routes/Pokedex.tsx index 3069e1e..0c452d4 100644 --- a/urmine-frontend/src/Routes/Pokedex.tsx +++ b/urmine-frontend/src/Routes/Pokedex.tsx @@ -1,4 +1,7 @@ +import { useEffect } from "react"; +import { useNavigate } from "react-router-dom"; import styled from "styled-components"; +import { getToken } from "../api/user"; import PokeSeal from "../components/PokeSeal"; import Search from "../components/Search"; @@ -278,7 +281,25 @@ const PokeContainer = styled.main` gap: 60px 0px; `; +let code = new URL(window.location.href).searchParams.get("code"); + function Pokedex() { + const navigate = useNavigate(); + + async function kakaoLogin(code: string) { + const data = JSON.parse(await getToken(code)); + if (data.status !== 500) { + localStorage.setItem("accessToken", data.accessToken); + navigate("/pokedex"); + } + } + + useEffect(() => { + if (code !== null) { + kakaoLogin(code); + } + }, []); + return ( <> diff --git a/urmine-frontend/src/api/user.ts b/urmine-frontend/src/api/user.ts index 4801f14..2880f9f 100644 --- a/urmine-frontend/src/api/user.ts +++ b/urmine-frontend/src/api/user.ts @@ -1,8 +1,13 @@ -const BASE_URL = "http://15.164.97.14:8080/api/user"; +const BASE_URL = "http://urmine.site:8080/api/user"; export async function getKakaoLoginPage() { - const url = await ( - await fetch("http://15.164.97.14:8080/api/user/kakao/page") - ).text(); + const url = await (await fetch(`${BASE_URL}/kakao/page`)).text(); return url; } + +export async function getToken(code: string) { + const token = await ( + await fetch(`${BASE_URL}/kakao/login?code=${code}`) + ).text(); + return token; +} From b4b25c3a4eea1709ce255a8954b7c66deaa21ea4 Mon Sep 17 00:00:00 2001 From: ohwoo-kwon Date: Tue, 21 Jun 2022 20:37:24 +0900 Subject: [PATCH 2/2] fix: DockerFile --- urmine-frontend/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/urmine-frontend/Dockerfile b/urmine-frontend/Dockerfile index 63bb3fa..3919632 100644 --- a/urmine-frontend/Dockerfile +++ b/urmine-frontend/Dockerfile @@ -4,6 +4,8 @@ WORKDIR /usr/src/app COPY . . +RUN npm install + RUN npm run build WORKDIR /usr/src/app/build