Skip to content

Commit

Permalink
Merge pull request #12 from StopSoo/forked
Browse files Browse the repository at this point in the history
api 연결을 통한 카카오 로그인 구현 완성 !
  • Loading branch information
sichoi42 authored Dec 8, 2023
2 parents e50589e + 26237dd commit 629b2af
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# misc
.DS_Store
.env.local
.env
.env.development.local
.env.test.local
.env.production.local
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^14.5.1",
"polished": "^4.2.2",
"react": "^18.2.0",
"react-cookie": "^6.1.1",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-responsive": "^9.0.2",
Expand Down
38 changes: 38 additions & 0 deletions pnpm-lock.yaml

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

15 changes: 15 additions & 0 deletions src/api/cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Cookies } from 'react-cookie';

const cookies = new Cookies();

export const setCookie = (key, value) => {
cookies.set(key, value, { path: '/' });
};

export const getCookie = (key) => {
return cookies.get(key);
};

export const removeCookie = (key) => {
cookies.remove(key, { path: '/' });
};
132 changes: 55 additions & 77 deletions src/component/login/LoginTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,52 @@ import googleLogo from '../resource/logo_google.png';

import WhiteBox from './WhiteBox'

function LoginTemplate () {
//추후 api 변경 시 같이 변경하기
const login = ({socialtype}) => {
try {
window.location.replace(
import.meta.env.REACT_APP_BE_HOST + `/api/v1/auth/login/oauth-types/${socialtype}`,
);
} catch (error) {
console.error("유효하지 않은 URL입니다!", error);
}
};
function LoginTemplate() {
const login = (socialtype) => {
try {
window.location.replace(
`${process.env.REACT_APP_BE_HOST}/api/v1/auth/login/oauth-types/${socialtype}`
);
} catch (error) {
console.error("유효하지 않은 URL입니다!", error);
}
};

return (
//align-items: center -> 적용이 안되는 문제로 우선 삭제
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%'}}>
<WhiteBox >
<h1 className="title">로그인하기</h1>
<h3>소셜 로그인으로 진행하세요</h3>
<HorizontalLine position="top"/>
<ButtonContainer >
<SocialLoginButton socialtype="kakao" onClick={() => login('kakao')}>
<SocialButtonIcon src={kakaoLogo} alt="카카오 로고" className="social-icon"/>
카카오 로그인
</SocialLoginButton>
<SocialLoginButton socialtype="naver" onClick={() => login(socialtype)}>
<SocialButtonIcon src={naverLogo} alt="네이버 로고" className="social-icon"/>
네이버 로그인
</SocialLoginButton>
<SocialLoginButton socialtype="google" onClick={() => login(socialtype)}>
<SocialButtonIcon src={googleLogo} alt="구글 로고" className="social-icon"/>
&nbsp; 구글 로그인
</SocialLoginButton>
</ButtonContainer >
<HorizontalLine position="top"/>
{/* <HorizontalLine position="bottom"/>
return (
//align-items: center -> 적용이 안되는 문제로 우선 삭제
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
<WhiteBox >
<h1 className="title">로그인하기</h1>
<h3>소셜 로그인으로 진행하세요</h3>
<HorizontalLine position="top" />
<ButtonContainer >
<SocialLoginButton socialtype="kakao" onClick={() => login('kakao')}>
<SocialButtonIcon src={kakaoLogo} alt="카카오 로고" className="social-icon" />
카카오 로그인
</SocialLoginButton>
<SocialLoginButton socialtype="naver" onClick={() => login('naver')}>
<SocialButtonIcon src={naverLogo} alt="네이버 로고" className="social-icon" />
네이버 로그인
</SocialLoginButton>
<SocialLoginButton socialtype="google" onClick={() => login('google')}>
<SocialButtonIcon src={googleLogo} alt="구글 로고" className="social-icon" />
&nbsp; 구글 로그인
</SocialLoginButton>
</ButtonContainer >
<HorizontalLine position="top" />
{/* <HorizontalLine position="bottom"/>
<SignInButton >회원가입하기</SignInButton > */}
</WhiteBox >
</div>
);
</WhiteBox >
</div>
);
};

const LineStyled = styled.span `
const LineStyled = styled.span`
flex: 1;
border-top: 1px solid var(--light-gray);
`;

const TextStyled = styled.span `
const TextStyled = styled.span`
padding: 0 35px;
color: var(--light-gray);
font-size: 22px;
Expand All @@ -67,18 +66,18 @@ const LineContainer = styled.div`
justify-content: center;
`;

const HorizontalLine = ({position}) => {
return (
<LineContainer>
{position === 'top' && <LineStyled />}
{position === 'bottom' && <LineStyled />}
{position === 'bottom' && <TextStyled>또는</TextStyled>}
{position === 'bottom' && <LineStyled />}
</LineContainer>
);
const HorizontalLine = ({ position }) => {
return (
<LineContainer>
{position === 'top' && <LineStyled />}
{position === 'bottom' && <LineStyled />}
{position === 'bottom' && <TextStyled>또는</TextStyled>}
{position === 'bottom' && <LineStyled />}
</LineContainer>
);
};

const ButtonContainer = styled.div`
const ButtonContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -100,15 +99,15 @@ const SocialLoginButton = styled.button`
&:hover { filter: brightness(95%); }
outline: none;
border: ${props =>
props.socialtype === 'google' ? '1px solid #D9D9D9' : 'none'};
border: ${props =>
props.socialtype === 'google' ? '1px solid #D9D9D9' : 'none'};
background-color: ${props =>
props.socialtype === 'naver' ? '#03c75a' :
props.socialtype === 'kakao' ? '#FEE500' :
props.socialtype === 'naver' ? '#03c75a' :
props.socialtype === 'kakao' ? '#FEE500' :
props.socialtype === 'google' ? '#FFF' : 'var(--white)'};
color: ${props =>
props.socialtype === 'naver' ? '#FFF' :
props.socialtype === 'kakao' ? '#000' :
props.socialtype === 'naver' ? '#FFF' :
props.socialtype === 'kakao' ? '#000' :
props.socialtype === 'google' ? '#000' : 'var(--black)'};
`;

Expand All @@ -119,25 +118,4 @@ const SocialButtonIcon = styled.img`
margin-right: 27%;
`;

//사이트 자체 로그인 지원 안하므로 삭제됨
// const SignInButton = styled.button`
// margin-left: auto;
// margin-right: auto;

// display: flex;
// align-items: center;
// justify-content: center;
// width: 400px;
// height: 50px;
// margin-top: 5%;
// border-radius: 12px;
// border : 1px solid var(--light-gray);
// background-color: var(--white);
// font-size: 14px;
// font-weight: 700;
// &:active { opacity: 0.4; }
// &:hover { filter: brightness(95%); }
// `;

export default LoginTemplate;

export default LoginTemplate;
8 changes: 4 additions & 4 deletions src/screen/MainScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useState } from 'react';
import styled from 'styled-components';
import BeforeLoginSet from '../component/main screen/BeforeLogin';
import AfterLoginSet from '../component/main screen/AfterLogin';
import { getCookie } from '../api/cookie';

/* 로그인 여부에 따라 다른 화면을 렌더링 */
function MainScreen(props) {
const [IsLogin, setIsLogin] = useState(0);
if (IsLogin) {
const token = getCookie('access_token');

if (!token) {
return(
<BeforeLoginSet />
);
Expand Down

0 comments on commit 629b2af

Please sign in to comment.