Skip to content

Commit 2e75883

Browse files
authored
Merge pull request #83 from DevKor-github/feat/#82/login-page
[#82] feat: login page κ΅¬ν˜„
2 parents 388ab00 + 4bdc839 commit 2e75883

8 files changed

Lines changed: 180 additions & 16 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import useGetIsLogin from '@/common/hooks/apis/useGetIsLogin';
2+
import { useEffect } from 'react';
3+
import { Outlet, useNavigate } from 'react-router';
4+
5+
/**
6+
* 둜그인 ν•΄μ•Όλ§Œ λ“€μ–΄κ°ˆ 수 μžˆλŠ” νŽ˜μ΄μ§€λ₯Ό κ°μ‹Έμ£ΌλŠ” μ»΄ν¬λ„ŒνŠΈ
7+
*/
8+
const AuthGuard = () => {
9+
const navigate = useNavigate();
10+
const { data: isLogin, isSuccess } = useGetIsLogin();
11+
12+
useEffect(() => {
13+
if (isSuccess && !isLogin) {
14+
navigate('/login', { replace: true });
15+
}
16+
}, [isLogin, isSuccess, navigate]);
17+
18+
if (!isLogin) return null;
19+
20+
return <Outlet />;
21+
};
22+
export default AuthGuard;

β€Žsrc/common/hooks/apis/useGetIsLogin.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const useGetIsLogin = () => {
1717
return useQuery({
1818
queryKey: ['isLogin'],
1919
queryFn: getIsLogin,
20+
staleTime: 0, // 맀번 확인
2021
});
2122
};
2223

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const GoogleLogo = () => {
2+
return (
3+
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="15" fill="none" viewBox="0 0 14 15">
4+
<mask
5+
id="mask0_560_3237"
6+
width="14"
7+
height="15"
8+
x="0"
9+
y="0"
10+
maskUnits="userSpaceOnUse"
11+
style={{ maskType: 'luminance' }}
12+
>
13+
<path fill="#fff" d="M14 .143H0v14h14z"></path>
14+
</mask>
15+
<g mask="url(#mask0_560_3237)">
16+
<path
17+
fill="#4285F4"
18+
d="M13.72 7.302q-.002-.744-.127-1.432H7v2.708h3.767a3.22 3.22 0 0 1-1.397 2.113v1.756h2.263c1.323-1.218 2.087-3.013 2.087-5.145"
19+
></path>
20+
<path
21+
fill="#34A853"
22+
d="M7 14.143c1.89 0 3.475-.627 4.633-1.696L9.37 10.691c-.626.42-1.428.668-2.37.668-1.823 0-3.366-1.231-3.917-2.886H.745v1.814A7 7 0 0 0 7 14.143"
23+
></path>
24+
<path
25+
fill="#FBBC04"
26+
d="M3.083 8.473c-.14-.42-.22-.868-.22-1.33 0-.461.08-.91.22-1.33V4H.745a7 7 0 0 0 0 6.287z"
27+
></path>
28+
<path
29+
fill="#E94235"
30+
d="M7 2.927c1.028 0 1.95.353 2.676 1.047l2.008-2.008C10.47.836 8.887.143 7 .143A7 7 0 0 0 .745 4l2.338 1.814C3.633 4.16 5.177 2.927 7 2.927"
31+
></path>
32+
</g>
33+
</svg>
34+
);
35+
};
36+
export default GoogleLogo;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const KakaoLogo = () => {
2+
return (
3+
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="14" fill="none" viewBox="0 0 15 14">
4+
<path
5+
fill="#000"
6+
fillRule="evenodd"
7+
d="M7.523.461c-3.954 0-7.16 2.476-7.16 5.53 0 1.9 1.24 3.574 3.128 4.57l-.794 2.902c-.07.256.223.46.448.312l3.482-2.298q.44.044.896.045c3.954 0 7.159-2.476 7.159-5.53S11.476.461 7.522.461"
8+
clipRule="evenodd"
9+
></path>
10+
</svg>
11+
);
12+
};
13+
export default KakaoLogo;

β€Žsrc/pages/LoginPage/index.tsxβ€Ž

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
1+
import { useEffect } from 'react';
2+
import { useNavigate } from 'react-router';
3+
14
import * as s from './style.css';
25

36
import SafeArea from '@/common/components/SafeArea';
7+
import useGetIsLogin from '@/common/hooks/apis/useGetIsLogin';
8+
import GoogleLogo from '@/libs/assets/GoogleLogo';
9+
import KakaoLogo from '@/libs/assets/KakaoLogo';
410

511
const LoginPage = () => {
12+
const navigate = useNavigate();
13+
const { data: isLogin, isLoading } = useGetIsLogin();
14+
15+
useEffect(() => {
16+
// TODO: μ›λž˜ 있던 νŽ˜μ΄μ§€λ‘œ
17+
if (isLogin) {
18+
navigate(-1);
19+
}
20+
}, [isLogin, navigate]);
21+
22+
if (isLoading || isLogin) return null;
23+
624
return (
725
<SafeArea>
826
<div className={s.Container}>
9-
<h1>μž„μ‹œ 둜그인 νŽ˜μ΄μ§€</h1>
10-
<a href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/kakao`}>카카였 둜그인</a>
11-
<a href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/google`}>ꡬ글 둜그인</a>
27+
<p className={s.Label}>SNS κ³„μ •μœΌλ‘œ λ‘œκ·ΈμΈν•˜κΈ°</p>
28+
<div className={s.ButtonContainer}>
29+
{/* TODO: μ• ν”Œ 둜그인 μΆ”κ°€ */}
30+
<a
31+
className={s.LoginButton({ src: 'google' })}
32+
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/google`}
33+
>
34+
<GoogleLogo />
35+
Google둜 둜그인
36+
</a>
37+
<a
38+
className={s.LoginButton({ src: 'kakao' })}
39+
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/kakao`}
40+
>
41+
<KakaoLogo />
42+
μΉ΄μΉ΄μ˜€ν†‘μœΌλ‘œ 둜그인
43+
</a>
44+
</div>
1245
</div>
1346
</SafeArea>
1447
);
Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
1-
import { css } from '@styled-system/css';
1+
import { css, cva } from '@styled-system/css';
22

33
export const Container = css({
4+
height: 'full',
45
display: 'flex',
56
flexDir: 'column',
6-
gap: '1rem',
7+
justifyContent: 'flex-end',
8+
alignItems: 'center',
9+
pb: '3.75rem',
10+
px: '1rem',
11+
gap: '1.875rem',
12+
});
13+
14+
export const Label = css({
15+
color: '80',
16+
fontSize: '0.875rem',
17+
fontWeight: 500,
18+
lineHeight: 'normal',
19+
});
20+
21+
export const ButtonContainer = css({
22+
display: 'flex',
23+
flexDir: 'column',
24+
gap: '0.5rem',
25+
width: 'full',
26+
});
27+
28+
export const LoginButton = cva({
29+
base: {
30+
display: 'flex',
31+
width: 'full',
32+
height: '3.125rem',
33+
rounded: '0.375rem',
34+
justifyContent: 'center',
35+
alignItems: 'center',
36+
fontSize: '1.125rem',
37+
fontWeight: 600,
38+
lineHeight: 1.5,
39+
},
40+
variants: {
41+
src: {
42+
apple: {
43+
bgColor: '#FFF',
44+
color: '#000',
45+
fontWeight: 590,
46+
fontFamily: 'SF Pro',
47+
},
48+
google: {
49+
bgColor: '#F2F2F2',
50+
gap: '0.75rem',
51+
color: '#1F1F1F',
52+
},
53+
kakao: {
54+
bgColor: '#FEE500',
55+
gap: '0.8rem',
56+
color: 'rgba(0, 0, 0, 0.85)',
57+
},
58+
},
59+
},
760
});

β€Žsrc/pages/routes.tsxβ€Ž

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,45 @@ import type { RouteObject } from 'react-router';
33
import HomePage from '@/pages/HomePage';
44
import Layout from '@/pages/Layout';
55
import PickPage from '@/pages/PickPage';
6+
import PostPage from './PostPages';
67
import PostPageRoutes from '@/pages/PostPages';
78
import NotFoundPage from '@/pages/NotFoundPage';
89
import DetailPage from '@/pages/DetailPage';
910
import LoginPage from '@/pages/LoginPage';
11+
import AuthGuard from '@/common/components/AuthGuard';
1012

1113
/**
1214
* μƒˆλ‘œμš΄ νŽ˜μ΄μ§€ μΆ”κ°€ν•˜κ³  μ‹ΆμœΌλ©΄ 여기에 μΆ”κ°€ν•˜λ©΄ λ©λ‹ˆλ‹€
1315
*/
1416
const routes: RouteObject[] = [
1517
{
16-
path: '/',
1718
element: <Layout />,
1819
children: [
1920
{
2021
path: '/',
2122
element: <HomePage />,
2223
},
23-
{
24-
path: '/pick',
25-
element: <PickPage />,
26-
},
27-
{
28-
path: '/post',
29-
element: <PostPageRoutes />,
30-
},
3124
{
3225
path: '/detail/:id',
3326
element: <DetailPage />,
3427
},
3528
{
36-
path: '/my', // TODO: μž„μ‹œ
29+
path: '/login', // TODO: μž„μ‹œ
3730
element: <LoginPage />,
3831
},
32+
{
33+
element: <AuthGuard />, // 둜그인 ν•΄μ•Όλ§Œ λ“€μ–΄κ°ˆ 수 μžˆλŠ” νŽ˜μ΄μ§€λŠ” 이 μ•„λž˜λ‹€κ°€ λ„£μ–΄μ£Όμ…ˆ
34+
children: [
35+
{
36+
path: '/pick',
37+
element: <PickPage />,
38+
},
39+
{
40+
path: '/post',
41+
element: <PostPage />,
42+
},
43+
],
44+
},
3945
{
4046
path: '*', // λͺ» μ°Ύμ•˜μ„ λ•Œ 404 νŽ˜μ΄μ§€λ‘œ 이동
4147
element: <NotFoundPage />,

β€Žvite.config.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import tsconfigPaths from 'vite-tsconfig-paths';
44

55
// https://vite.dev/config/
66
export default defineConfig({
7-
base: '/repicka-web/', // TODO: BASE_URL μΆ”ν›„ μˆ˜μ •
7+
base: '/repicka-web', // TODO: BASE_URL μΆ”ν›„ μˆ˜μ •
88
plugins: [react(), tsconfigPaths()],
99
});

0 commit comments

Comments
Β (0)