Skip to content

Commit

Permalink
Merge pull request #1063 from MinCheolS/part3-신민철-week16
Browse files Browse the repository at this point in the history
[신민철] week16
  • Loading branch information
arthurkimdev authored May 2, 2024
2 parents 74f8fde + d6ebee0 commit 42e1a2b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 35 deletions.
27 changes: 27 additions & 0 deletions pages/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,30 @@ export const getSelectLinksInfo = async (folderId: number) => {
const result = response.json();
return result;
};

export const signInUser = async (email: string, password: string) => {
const userInfo = {
email: email,
password: password,
};

try {
const response = await fetch('https://bootcamp-api.codeit.kr/api/sign-in', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userInfo),
});

if (response.status === 200) {
const result = await response.json();
localStorage.setItem('accessToken', result.data.accessToken);
return true;
} else {
return false;
}
} catch (error) {
console.log(error);
}
};
45 changes: 18 additions & 27 deletions pages/signin.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useState } from 'react';
import Link from 'next/link';
import styles from '@/styles/Signin.module.css';
import { emailRegex, passwordRegex } from '@/components/Regex';
import logo from '@/public/logo.svg';
import kakao from '@/public/kakao logo.svg';
import google from '@/public/google.svg';
import passwordOff from '@/public/passwordOff.svg';
import passwordOn from '@/public/passwordOn.svg';
import styles from '@styles/Signin.module.css';
import { emailRegex, passwordRegex } from '@components/Regex';
import logo from '@public/logo.svg';
import kakao from '@public/kakao logo.svg';
import google from '@public/google.svg';
import passwordOff from '@public/passwordOff.svg';
import passwordOn from '@public/passwordOn.svg';
import { signInUser } from './api/api';

export default function Signin() {
const [email, setEmail] = useState('');
Expand Down Expand Up @@ -59,27 +60,17 @@ export default function Signin() {
const handleSubmit = async (e: React.ChangeEvent<HTMLButtonElement>) => {
e.preventDefault();

const userInfo = {
email: email,
password: password,
};
try {
const signIn = await signInUser(email, password);

const response = await fetch('https://bootcamp-api.codeit.kr/api/sign-in', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userInfo),
});

if (response.status === 200) {
const result = await response.json();
localStorage.setItem('accessToken', result.data.accessToken);
window.location.assign('folder.html');
return;
} else {
setEmailError('이메일을 확인해 주세요.');
setPasswordError('비밀번호를 확인해 주세요.');
if (signIn) {
window.location.assign('folder.html');
} else {
setEmailError('이메일을 확인해 주세요.');
setPasswordError('비밀번호를 확인해 주세요.');
}
} catch (error) {
console.log(error);
}
};

Expand Down
14 changes: 7 additions & 7 deletions pages/signup.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useState } from 'react';
import Link from 'next/link';
import styles from '@/styles/Signup.module.css';
import logo from '@/public/logo.svg';
import kakao from '@/public/kakao logo.svg';
import google from '@/public/google.svg';
import passwordOff from '@/public/passwordOff.svg';
import passwordOn from '@/public/passwordOn.svg';
import { emailRegex, passwordRegex } from '@/components/Regex';
import styles from '@styles/Signup.module.css';
import logo from '@public/logo.svg';
import kakao from '@public/kakao logo.svg';
import google from '@public/google.svg';
import passwordOff from '@public/passwordOff.svg';
import passwordOn from '@public/passwordOn.svg';
import { emailRegex, passwordRegex } from '@components/Regex';

export default function Signup() {
const [email, setEmail] = useState('');
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"jsx": "preserve",
"incremental": true,
"paths": {
"@/*": ["./*"]
"@*": ["./*"],
"@components": ["./*/components"],
"@public": ["./*/public"],
"@styles": ["./*/styles"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
Expand Down

0 comments on commit 42e1a2b

Please sign in to comment.