From fdb2218f15ba489d2231a005c10fda73b5f547e4 Mon Sep 17 00:00:00 2001 From: ssafy_kyz Date: Thu, 1 Apr 2021 03:13:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EC=A4=91=EA=B0=84=20=EC=BB=A4=EB=B0=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Signin/signin.stories.tsx | 0 components/Signin/signin.tsx | 81 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 components/Signin/signin.stories.tsx create mode 100644 components/Signin/signin.tsx diff --git a/components/Signin/signin.stories.tsx b/components/Signin/signin.stories.tsx new file mode 100644 index 0000000..e69de29 diff --git a/components/Signin/signin.tsx b/components/Signin/signin.tsx new file mode 100644 index 0000000..bc895eb --- /dev/null +++ b/components/Signin/signin.tsx @@ -0,0 +1,81 @@ +import React, { useState } from 'react'; +import styled from '@emotion/styled'; +import Link from 'next/link'; +import Router from 'next/router'; +// import Input from '../input' +// import Input from '../Input' +import axios from 'axios'; +// import * as logo from 'asset/instagramLogo.png' + +export type SignInInputList = { + email: string, + password: string, +}; + +export const Signin = () => { + const [inputs, setInputs] = useState({ + email: '', + password: '', + }); + const { email, password } = inputs; + const [buttonActive, setButtonActive] = useState(false); + const [showSignInValidResult, setShowSignInValidResult] = useState(false); + const signinValidation = () : void => { + let value = false; + if (email && password.length > 6) value = true; + setButtonActive(value); + }; + + const onChangeHandler = (event: React.ChangeEvent) : void => { + setInputs({ + ...inputs, + [event.target.name]: event?.target.value, + }); + signinValidation(); + }; + + +} + + + + + + + + + + + + +return ( + + + {/* */} + 친구들의 사진과 동영상을 보려면 가입하세요. +
+ + + +
+ {/* {showSignUpValidResult && 가입 형식에 맞지 않습니다.} */} + +
+ +
계정이 없으신가요?
+ + 가입하기 + +
+
+); +}; \ No newline at end of file From c1539075bdec81822112bac11f36b17d012c8975 Mon Sep 17 00:00:00 2001 From: ssafy_kyz Date: Sat, 3 Apr 2021 19:54:39 +0900 Subject: [PATCH 2/2] =?UTF-8?q?issue/20=20[#20=5F2]=20aync=20await=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Signin/signin.tsx | 129 +++++++++++++++++++++++------------ pages/users/index.tsx | 26 +++++++ 2 files changed, 112 insertions(+), 43 deletions(-) diff --git a/components/Signin/signin.tsx b/components/Signin/signin.tsx index bc895eb..7d12aae 100644 --- a/components/Signin/signin.tsx +++ b/components/Signin/signin.tsx @@ -29,53 +29,96 @@ export const Signin = () => { const onChangeHandler = (event: React.ChangeEvent) : void => { setInputs({ ...inputs, - [event.target.name]: event?.target.value, + [event.target.name]: event.target.value, }); signinValidation(); }; - -} - - - - - - - - - + const onClickHandler = async () => { + const emailRegex = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/.test(email) + const passwordRegex = /(?=.*\d)(?=.*[a-z]).{8,}/.test(password); + // console.log(`이메일 형식 : ${emailRegex}, 비밀번호 형식 : ${passwordRegex}`); + + const result = await axios.get(`http://127.0.0.1:8080/auth/signin`); + + try { + if (emailRegex && passwordRegex) { + axios({ + method: 'post', + url: 'http://127.0.0.1:8080/auth/signin', + data: { + email, + password, + } + }) + .then(()=>{ + setShowSignInValidResult(true) + console.log('로그인'); + Router.push({ + pathname: '/feed', + )}; + }) + } catch(error) { + console.log(error); + } + }; + // let status: number =0; + // let data: {} = {}; + + // if (!BASE_URL) { + // try { + // await; + // status = 200; + // data = + // } catch (error) { + + // } + // } else { + // try { + // await axios.post(BASE_URL + "/api/signin", req).then((res) => { + // status = res.status; + // data + // }) + // } catch (error) + // } + + + + + return ( + + + {/* */} + 친구들의 사진과 동영상을 보려면 가입하세요. +
+ + + +
+ {/* {showSignUpValidResult && 가입 형식에 맞지 않습니다.} */} + +
+ +
계정이 없으신가요?
+ + 가입하기 + +
+
+ ); +}; +const Container = styled.div` + display: flex; -return ( - - - {/* */} - 친구들의 사진과 동영상을 보려면 가입하세요. -
- - - -
- {/* {showSignUpValidResult && 가입 형식에 맞지 않습니다.} */} - -
- -
계정이 없으신가요?
- - 가입하기 - -
-
-); -}; \ No newline at end of file +`; \ No newline at end of file diff --git a/pages/users/index.tsx b/pages/users/index.tsx index 1c788ab..d373759 100644 --- a/pages/users/index.tsx +++ b/pages/users/index.tsx @@ -26,6 +26,8 @@ const WithStaticProps = ({ items }: Props) => ( ) + + export const getStaticProps: GetStaticProps = async () => { // Example for including static props in a Next.js function component page. // Don't forget to include the respective types for any props passed into @@ -35,3 +37,27 @@ export const getStaticProps: GetStaticProps = async () => { } export default WithStaticProps + +export const EMAIL_SIGNIN = async(req) => { + let status: number = 0; + let data: {} = {}; + + if (!API_DEV) { + try { + status = 200; + data = EmailSigninData.data; + } catch (error) { + + } + } else { + try { + await axios.post(BASE_URL + "/api/signin", req).then((res) => { + status = res.status; + data = res.data.data; + }); + } catch (error) { + + } + } + return { status, data }; +} \ No newline at end of file