Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 카카오 소셜 로그인 로직 구현 및 통신 #35

Draft
wants to merge 24 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4cfccef
feat: 카카오 소셜 로그인 로직 구현 및 통신
gkfla668 Feb 4, 2025
bee20de
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-12th-5-…
gkfla668 Feb 7, 2025
33e9938
fix: KAKAO_AUTH_URL 수정
gkfla668 Feb 8, 2025
9f7cbb0
fix: 리다이렉션 페이지 수정 및 로딩 애니메이션 추가
gkfla668 Feb 8, 2025
de8de2e
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-12th-5-…
gkfla668 Feb 8, 2025
7fcc1a3
feat: 로그인 성공 toast 컴포넌트 추가
gkfla668 Feb 8, 2025
8e97bd0
fix: ESLint 오류 + pre-push 훅 오류 수정
gkfla668 Feb 8, 2025
99aae56
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-12th-5-…
gkfla668 Feb 13, 2025
f8ec530
feat: '카카오톡으로 시작하기' 버튼 컴포넌트
gkfla668 Feb 13, 2025
5afed3b
feat: 온보딩 화면 컴포넌트
gkfla668 Feb 13, 2025
987d55d
design: framer motion 컴포넌트 분리 및 적용
gkfla668 Feb 13, 2025
f69aad5
refactor: 로딩 컴포넌트 적용
gkfla668 Feb 13, 2025
14cf0da
feat: home에서 로그인 페이지 접근 로직 추가
gkfla668 Feb 13, 2025
be68d50
Merge branch 'dev' into design/login
gkfla668 Feb 13, 2025
1d0d3e9
fix: 설정 페이지 카카오 svg 파일 지워버려서 다시 추가
gkfla668 Feb 13, 2025
0609d62
Merge branch 'design/login' of https://github.com/dnd-side-project/dn…
gkfla668 Feb 13, 2025
67d2e7b
feat: 로그인 페이지 내 온보딩 화면 조건부 렌더링
gkfla668 Feb 13, 2025
9e6f658
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-12th-5-…
gkfla668 Feb 14, 2025
357f95a
Merge branch 'design/login' of https://github.com/dnd-side-project/dn…
gkfla668 Feb 14, 2025
eb2684e
feat: 프록시 설정
gkfla668 Feb 14, 2025
72046c3
feat: 리다이렉트 페이지지 경로 수정, 상대 경로 설정
gkfla668 Feb 15, 2025
e2037cf
fix: process.env.NEXT_PUBLIC_API_URL 빌드 에러 수정
gkfla668 Feb 15, 2025
df9824b
fix: process.env.NEXT_PUBLIC_API_URL 빌드 에러, 절대 경로로 수정
gkfla668 Feb 15, 2025
f29f806
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-12th-5-…
gkfla668 Feb 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel
Expand Down
11 changes: 10 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
async rewrites() {
return [
{
source: "/api/v1/:path*",
destination: 'https://api.picktory.net/api/v1/:path*',
},
];
},
};

export default nextConfig;
79 changes: 76 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
"dependencies": {
"@radix-ui/react-dialog": "^1.1.5",
"@radix-ui/react-slot": "^1.1.2",
"@radix-ui/react-toast": "^1.2.6",
"@radix-ui/react-tooltip": "^1.1.7",
"@tanstack/react-query": "^5.66.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"embla-carousel-react": "^8.5.2",
"framer-motion": "^12.4.2",
"lucide-react": "^0.474.0",
"next": "14.2.23",
"react": "^18",
Expand Down
File renamed without changes
3 changes: 3 additions & 0 deletions public/icons/logo_kakao.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
28 changes: 28 additions & 0 deletions src/app/PageTransition.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";

import { usePathname } from "next/navigation";
import { AnimatePresence, motion } from "framer-motion";

export default function PageTransition({
children,
}: {
children: React.ReactNode;
}) {
const pathname = usePathname();

return (
<AnimatePresence mode="wait">
<motion.div
key={pathname}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 1 }}
transition={{
duration: 0.5,
}}
>
{children}
</motion.div>
</AnimatePresence>
);
}
60 changes: 60 additions & 0 deletions src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use client";

import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";

import Onboarding from "@/components/Onboarding";
import KakaoLoginButton from "@/components/KakaoLoginButton";

const Page = () => {
const REST_API_KEY = process.env.NEXT_PUBLIC_REST_API_KEY;
const REDIRECT_URI = process.env.NEXT_PUBLIC_REDIRECT_URI;

const KAKAO_AUTH_URL = `https://kauth.kakao.com/oauth/authorize?response_type=code&client_id=${REST_API_KEY}&redirect_uri=${REDIRECT_URI}`;

const [isOnboardingComplete, setIsOnboardingComplete] = useState(false);

const handleOnboardingComplete = () => {
setIsOnboardingComplete(true);
};

return (
<AnimatePresence mode="wait">
{!isOnboardingComplete ? (
<motion.div
key="/auth/login"
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 20 }}
transition={{ duration: 0.5 }}
className="h-full"
>
<Onboarding onComplete={handleOnboardingComplete} />
</motion.div>
) : (
<motion.div
key="login"
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -20 }}
transition={{ duration: 0.5 }}
className="h-full"
>
<div className="w-full h-full flex flex-col justify-center items-center">
<section className="w-[340px] h-[442px] bg-gray-100">
그래픽
</section>
<p className="text-center">
선물 보따리를 안전하게 보관하기 위해서는 <br /> 로그인이 필요해요!
</p>
</div>
<div className="w-full absolute bottom-4 px-4">
<KakaoLoginButton link={KAKAO_AUTH_URL} />
</div>
</motion.div>
)}
</AnimatePresence>
);
};

export default Page;
72 changes: 72 additions & 0 deletions src/app/kakao/callback/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"use client";

import { useRouter, useSearchParams } from "next/navigation";
import { useEffect } from "react";

import { useMutation } from "@tanstack/react-query";
import Loading from "@/components/common/Loading";
import { toast } from "@/hooks/use-toast";

const Page = () => {
const searchParams = useSearchParams();
const router = useRouter();
const code = searchParams?.get("code");

const { mutate } = useMutation({
mutationFn: async (code: string) => {
const response = await fetch("/api/v1/oauth/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ code: code }),
});

if (!response.ok) {
throw new Error("로그인 실패");
}

const text = await response.text();
try {
const data = JSON.parse(text);
return data;
} catch {
throw new Error("응답 처리 실패");
}
},
onSuccess: (data) => {
console.log(data);

// 토큰 저장
localStorage.setItem("accessToken", data.result.accessToken);
localStorage.setItem("refreshToken", data.result.refreshToken);

toast({
title: "로그인 성공",
description: "로그인 되었습니다.",
});

router.push("/"); // 로그인 후 홈으로
},
onError: (error) => {
console.error("로그인 실패:", error);
},
});

useEffect(() => {
console.log("Code", code);

if (code) {
mutate(code);
}
}, [code]);

return (
<div className="h-full w-full flex items-center justify-center">
<Loading />
</div>
);
};

export default Page;
23 changes: 19 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import type { Metadata } from "next";
import { Suspense } from "react";
import localFont from "next/font/local";

import "./globals.css";

import Header from "@/layout/Header";
import { Suspense } from "react";
import { Toaster } from "@/components/ui/toaster";
import PageTransition from "@/app/PageTransition";

import { Providers } from "./providers";

const pretendard = localFont({
src: "./fonts/PretendardVariable.woff2",
variable: "--font-pretendard",
weight: "100 200 300 400 500 600 700 800 900",
});

const nanumSquareRound = localFont({
src: "./fonts/NanumSquareRound.ttf",
variable: "--font-nanum-square-round",
Expand All @@ -33,9 +40,17 @@ export default function RootLayout({
<div className="max-w-[430px] min-w-[375px] mx-auto bg-white min-h-screen flex flex-col relative">
<Suspense>
<Header />
<div className="flex-grow" style={{ height: "calc(100vh - 56px)" }}>
{children}
</div>
<Providers>
<PageTransition>
<div
className="flex-grow"
style={{ height: "calc(100vh - 56px)" }}
>
{children}
</div>
</PageTransition>
<Toaster />
</Providers>
</Suspense>
</div>
</body>
Expand Down
Loading