Skip to content

Commit

Permalink
feat(login): 구글 로그인 (#53)
Browse files Browse the repository at this point in the history
* f

* f

* f
  • Loading branch information
Collection50 authored Aug 30, 2024
1 parent 146fd16 commit 9a7fe3c
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 335 deletions.
172 changes: 28 additions & 144 deletions .pnp.cjs

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@react-oauth/google": "^0.12.1",
"@tanstack/react-query": "^5.51.1",
"@tanstack/react-query-devtools": "^5.51.1",
"@tippyjs/react": "^4.2.6",
Expand Down Expand Up @@ -75,7 +76,6 @@
"lowlight": "^3.1.0",
"lucide-react": "^0.411.0",
"next": "14.2.4",
"next-auth": "5.0.0-beta.18",
"react": "^18",
"react-colorful": "^5.6.1",
"react-day-picker": "8.10.1",
Expand Down
8 changes: 8 additions & 0 deletions src/app/GoogleProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { StrictPropsWithChildren } from '@/types';
import { GoogleOAuthProvider } from '@react-oauth/google';

export function GoogleProvider({ children }: StrictPropsWithChildren) {
const clientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENTID!;

return <GoogleOAuthProvider clientId={clientId}>{children}</GoogleOAuthProvider>;
}
3 changes: 0 additions & 3 deletions src/app/api/auth/[...nextauth]/route.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import '@/styles/globals.css';
import '@/styles/memo.css';
import { Inter } from 'next/font/google';
import { cn } from '@/utils';
import { SessionProvider } from 'next-auth/react';
import { Suspense } from 'react';
import { GoogleProvider } from '@/app/GoogleProvider';

const inter = Inter({ subsets: ['latin'] });

Expand All @@ -26,9 +26,9 @@ export default function RootLayout({
<html lang="en">
<body className={cn(inter.className, 'bg-neutral-1')}>
<QueryProvider>
<SessionProvider>
<GoogleProvider>
<Suspense>{children}</Suspense>
</SessionProvider>
</GoogleProvider>
</QueryProvider>
</body>
</html>
Expand Down
5 changes: 0 additions & 5 deletions src/app/login/actions.ts

This file was deleted.

9 changes: 8 additions & 1 deletion src/app/login/api/postLogin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { http } from '@/apis/http';
import { useMutation } from '@tanstack/react-query';

export const postLogin = (provider: 'GOOGLE' | 'KAKAO', token: string) =>
export const postLogin = ({ provider, token }: { provider: 'GOOGLE' | 'KAKAO'; token: string }) =>
http.post<{ accessToken: string; refreshToken: string; isFirstLogin: boolean }>({
url: '/users/social-login',
params: {
Expand All @@ -10,3 +11,9 @@ export const postLogin = (provider: 'GOOGLE' | 'KAKAO', token: string) =>
'SOCIAL-AUTH-TOKEN': token,
},
});

export const usePostLogin = () =>
useMutation({
mutationKey: ['post-login'],
mutationFn: postLogin,
});
36 changes: 30 additions & 6 deletions src/app/login/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,36 @@
import { motion } from 'framer-motion';
import { TouchButton } from '@/components/TouchButton';
import { Icon } from '@/system/components';
import { googleLogin } from '../actions';
import { useGoogleLogin } from '@react-oauth/google';
import { usePostLogin } from '../api/postLogin';
import { useFunnelContext } from '@/system/components/Funnel/useFunnel';
import { ACCESS_TOKEN, JOB_SELECTION, REFRESH_TOKEN, SELECT, NONE } from '@/app/login/constants/token';
import { setCookie } from 'cookies-next';

export function Login() {
const { mutate } = usePostLogin();
const { setStep } = useFunnelContext();
const login = useGoogleLogin({
onSuccess: (res) => {
mutate(
{ provider: 'GOOGLE', token: res.access_token },
{
onSuccess: ({ data: { isFirstLogin, accessToken, refreshToken } }) => {
const jobSelection = isFirstLogin ? NONE : SELECT;
setCookie(ACCESS_TOKEN, accessToken);
setCookie(REFRESH_TOKEN, refreshToken);
setCookie(JOB_SELECTION, jobSelection);

setStep('select');
},
},
);
},
onError: (res) => console.log('fail', res),
});

return (
<motion.form
<motion.div
initial={{
opacity: 0,
y: 150,
Expand All @@ -18,10 +43,9 @@ export function Login() {
}}
exit={{
opacity: 0,
x: 120,
x: -120,
}}
transition={{ duration: 1 }}
action={googleLogin}
className="w-552 h-604 p-68 pt-116 flex flex-col justify-between rounded-30 bg-[white]">
<div className="flex flex-col items-center gap-16">
<Icon name="cloverLogo" size={74} />
Expand All @@ -34,13 +58,13 @@ export function Login() {
</div>

<div className="flex flex-col gap-12">
<TouchButton type="submit" className="relative h-62 rounded-54 bg-[#F2F2F2]">
<TouchButton onClick={() => login()} type="submit" className="relative h-62 rounded-54 bg-[#F2F2F2]">
<div className="absolute top-6 left-6">
<Icon name="google" size={50} />
</div>
<p className="font-semibold tracking-[-0.091px]">구글로 시작하기</p>
</TouchButton>
</div>
</motion.form>
</motion.div>
);
}
Loading

0 comments on commit 9a7fe3c

Please sign in to comment.