diff --git a/components/AddLinkIcon.tsx b/components/AddLinkIcon.tsx
deleted file mode 100644
index c1adc724e..000000000
--- a/components/AddLinkIcon.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import React, { SVGProps } from 'react';
-
-const LinkIcon = (props: SVGProps) => (
-
-
-
-
-
-
-)
-
-export default LinkIcon;
diff --git a/components/FolderList.tsx b/components/FolderList.tsx
index 4227e61c7..b38d2a0ed 100644
--- a/components/FolderList.tsx
+++ b/components/FolderList.tsx
@@ -1,12 +1,11 @@
import { useState } from "react";
import { LinkCardData } from "@/types/type";
-import Button from "./Button";
-import styles from "@/styles/FolderList.module.css";
-import plusIcon from "@/public/images/Icon_plus.svg";
import LinkList from "./LinkList";
-import AddModal from "@/modal/addModal/AddModal";
import FolderMenu from "./FolderMenu";
-import Image from "next/image";
+import AddModal from "@/modal/addModal/AddModal";
+import PlusIcon from "@/public/images/Icon_plus.svg";
+import Button from "./Button";
+import styles from "@/styles/FolderList.module.css";
const FIRST_SELECTED_FOLDER = "전체";
@@ -47,7 +46,7 @@ function FolderList({ keyword, linkData, folderNameList, currentId, folderName,
폴더 추가
-
+
diff --git a/components/FolderMenu.tsx b/components/FolderMenu.tsx
index d33fc46fc..9cf2e0c5e 100644
--- a/components/FolderMenu.tsx
+++ b/components/FolderMenu.tsx
@@ -1,7 +1,7 @@
import { useState } from "react";
-import shareIcon from "@/public/images/Icon_share.svg";
-import editIcon from "@/public/images/Icon_edit.svg";
-import deleteIcon from "@/public/images/Icon_delete.svg";
+import ShareIcon from "@/public/images/Icon_share.svg";
+import EditIcon from "@/public/images/Icon_edit.svg";
+import DeleteIcon from "@/public/images/Icon_delete.svg";
import DeleteModal from "@/modal/deleteModal/DeleteModal";
import EditModal from "@/modal/editModal/EditModal";
import ShareModal from "@/modal/shareModal/ShareModal";
@@ -29,17 +29,17 @@ function FolderMenu({ placeholder }: Props) {
return (
-
+
공유
-
+
이름 변경
-
+
삭제
diff --git a/components/Footer.tsx b/components/Footer.tsx
index cb102ee0e..fcf3b0f48 100644
--- a/components/Footer.tsx
+++ b/components/Footer.tsx
@@ -1,7 +1,7 @@
-import facebook from '@/public/images/facebook.svg';
-import twitter from '@/public/images/twitter.svg';
-import youtube from '@/public/images/youtube.svg';
-import instagram from '@/public/images/instagram.svg';
+import Facebook from '@/public/images/facebook.svg';
+import Twitter from '@/public/images/twitter.svg';
+import Youtube from '@/public/images/youtube.svg';
+import Instagram from '@/public/images/instagram.svg';
import styles from '@/styles/Footer.module.css';
import Link from 'next/link';
import Image from 'next/image';
@@ -17,16 +17,16 @@ function Footer() {
-
+
-
+
-
+
-
+
diff --git a/components/Header.tsx b/components/Header.tsx
index 0dbc5dd49..e29ab5e85 100644
--- a/components/Header.tsx
+++ b/components/Header.tsx
@@ -6,7 +6,7 @@ interface Props {
name: string,
};
folderOwnerData:{
- profileImageSource: string,
+ image_source: string,
name: string,
};
}
@@ -14,7 +14,13 @@ interface Props {
function Header({folderData, folderOwnerData}: Props) {
return (
-
+
{folderOwnerData.name}
{folderData.name}
diff --git a/components/LinkAdd.tsx b/components/LinkAdd.tsx
index ff8da034e..db04047b3 100644
--- a/components/LinkAdd.tsx
+++ b/components/LinkAdd.tsx
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react';
import styles from '@/styles/LinkAdd.module.css';
import AddLinkModal from '@/modal/addLinkModal/AddLinkModal';
-import LinkIcon from './AddLinkIcon';
+import LinkIcon from '@/public/images/Icon_link.svg';
function LinkAdd() {
const [isAddLinkModalOpen, setIsAddLinkModalOpen] = useState(false);
diff --git a/components/LinkCard.tsx b/components/LinkCard.tsx
index c89c6b00a..3891aa209 100644
--- a/components/LinkCard.tsx
+++ b/components/LinkCard.tsx
@@ -2,20 +2,18 @@ import { MouseEvent, useState } from 'react';
import { LinkCardData } from '@/types/type';
import formatDate from '@/utils/formatDate';
import diffTime from '@/utils/diffTime';
-import star from '@/public/images/Icon_star.svg';
-import kebab from '@/public/images/Icon_kebab.svg'
-import noImg from '@/public/images/noImg.svg';
-import styles from '@/styles/LinkCard.module.css';
import Popover from './Popover';
-import Image from 'next/image';
import Link from 'next/link';
+import Star from '@/public/images/Icon_star.svg';
+import Kebab from '@/public/images/Icon_kebab.svg'
+import styles from '@/styles/LinkCard.module.css';
interface Props {
item: LinkCardData
}
-function LinkCard({item: {url, id, imageSource, createdAt, description}}: Props) {
+function LinkCard({item: {url, id, image_source, created_at, description}}: Props) {
const [isOpen, setIsOpen] = useState(false);
const handleClick = (e: MouseEvent) => {
@@ -26,19 +24,19 @@ function LinkCard({item: {url, id, imageSource, createdAt, description}}: Props)
return (
-
+
-
+
-
{diffTime(createdAt)}
+
{diffTime(created_at)}
{description}
-
{formatDate(createdAt)}
+
{formatDate(created_at)}
diff --git a/components/Navbar.tsx b/components/Navbar.tsx
index 651e2f09e..0d7bc6ff3 100644
--- a/components/Navbar.tsx
+++ b/components/Navbar.tsx
@@ -1,4 +1,4 @@
-import linkbraryLogo from '@/public/images/logo.svg';
+import LinkbraryLogo from '@/public/images/logo.svg';
import styles from '@/styles/Navbar.module.css';
import Image from 'next/image';
import Link from 'next/link';
@@ -7,7 +7,7 @@ interface Props {
className: string;
profileData: {
email: string,
- profileImageSource: string,
+ image_source: string,
};
isLoginStatus: boolean;
}
@@ -15,10 +15,12 @@ interface Props {
function NavigationBar({ className, profileData, isLoginStatus }: Props) {
return (
-
+
+
+
{isLoginStatus ? (
)
diff --git a/components/SearchBar.tsx b/components/SearchBar.tsx
index cda108a37..65f51449f 100644
--- a/components/SearchBar.tsx
+++ b/components/SearchBar.tsx
@@ -1,7 +1,7 @@
import { ChangeEvent, KeyboardEvent, MouseEvent } from 'react';
import styles from '@/styles/SearchBar.module.css';
-import CloseIconImage from './CloseIconImage';
-import SearchIconImage from './SearchIconImage';
+import CloseIcon from '@/public/images/Icon_close.svg';
+import SearchIcon from '@/public/images/Icon_search.svg';
interface Props {
inputValue: string;
@@ -28,7 +28,7 @@ function SearchBar({ inputValue, searchWord, onChange, onClick, onSubmit }: Prop
-
+
@@ -50,7 +51,7 @@ export default function Home() {
나만의 폴더를 무제한으로 만들고
다양하게 활용할 수 있습니다.
-
+
@@ -63,7 +64,7 @@ export default function Home() {
가족, 친구, 동료들에게 쉽고 빠르게 링크를
공유해 보세요.
-
+
@@ -74,7 +75,7 @@ export default function Home() {
중요한 정보들을 검색으로 쉽게 찾아보세요.
-
+
diff --git a/pages/shared.tsx b/pages/shared/[folderId].tsx
similarity index 56%
rename from pages/shared.tsx
rename to pages/shared/[folderId].tsx
index ce380d4f5..6fb8ab66c 100644
--- a/pages/shared.tsx
+++ b/pages/shared/[folderId].tsx
@@ -1,32 +1,36 @@
-import { getSampleFolderLinks, getSampleUserInfo } from "@/utils/api";
-import { ChangeEvent, MouseEvent, useEffect, useState } from "react";
-import { Data } from "@/types/type";
+import { getSharedFolderInfo, getSharedFolderLinks, getSharedFolderOwner, getUserInfo } from "@/utils/api";
+import { ChangeEvent, MouseEvent, useCallback, useEffect, useState } from "react";
+import { LinkCardData } from "@/types/type";
import Footer from "@/components/Footer";
import Header from "@/components/Header";
import LinkList from "@/components/LinkList";
import NavigationBar from "@/components/Navbar";
import SearchBar from "@/components/SearchBar";
+import { useRouter } from "next/router";
const INITIAL_PROFILE = {
- profileImageSource: '',
+ image_source: '',
email: '',
}
const INITIAL_FOLDER= {
name: '',
}
const INITIAL_FOLDER_OWNER = {
- profileImageSource: '',
+ image_source: '',
name: '',
}
export default function SharedPage() {
const [isLoginStatus, setIsLoginStatus] = useState(false);
const [profileData, setProfileData] = useState(INITIAL_PROFILE);
+ const [userId, setUserId] = useState(0);
const [folderData, setFolderData] = useState(INITIAL_FOLDER);
const [folderOwnerData, setFolderOwnerData] = useState(INITIAL_FOLDER_OWNER);
- const [linkData, setLinkData] = useState([]);
+ const [linkData, setLinkData] = useState([]);
const [search, setSearch] = useState('');
const [searchWord, setSearchWord] = useState('');
+ const router = useRouter();
+ const { folderId } = router.query;
const handleChange = (e: ChangeEvent) => {
setSearch(e.target.value);
@@ -42,11 +46,12 @@ export default function SharedPage() {
};
const getProfileData = async () => {
- const data = await getSampleUserInfo();
+ const { data } = await getUserInfo();
if (!data) return;
- setProfileData(data);
+ setProfileData(data[0]);
+ setUserId(data[0].id);
setIsLoginStatus(true);
}
@@ -54,19 +59,42 @@ export default function SharedPage() {
getProfileData();
}, []);
- const getFolderData = async () => {
- const { folder } = await getSampleFolderLinks();
+ const getFolderOwnerData = useCallback(async () => {
+ const { data } = await getSharedFolderOwner(userId);
- if (!folder) return;
+ if (!data[0]) return;
- setFolderData(folder);
- setFolderOwnerData(folder.owner);
- setLinkData(folder.links);
- }
+ setFolderOwnerData(data[0]);
+ }, [userId])
+
+ useEffect(() => {
+ getFolderOwnerData();
+ }, [getFolderOwnerData]);
+
+ const getFolderData = useCallback(async () => {
+ const { data } = await getSharedFolderInfo(folderId);
+
+ if (!data[0]) return;
+
+ setFolderData(data[0]);
+ }, [folderId])
useEffect(() => {
getFolderData();
- }, [])
+ }, [getFolderData])
+
+ const getFolderLinksData = useCallback(async () => {
+ const { data } = await getSharedFolderLinks(userId, folderId);
+
+ if (!data) return;
+
+ setFolderData(data);
+ setLinkData(data);
+ }, [userId, folderId])
+
+ useEffect(() => {
+ getFolderLinksData();
+ }, [getFolderLinksData])
return (
<>
diff --git a/pages/signin.tsx b/pages/signin.tsx
index ae4536853..35c649689 100644
--- a/pages/signin.tsx
+++ b/pages/signin.tsx
@@ -1,24 +1,25 @@
-import { SIGNIN } from "@/constants/signInput_constant";
-import { useRouter } from "next/router";
import { ChangeEvent, KeyboardEvent, useEffect, useState } from "react";
import { validEmailInput, validPasswordInput } from "@/utils/checkValid";
+import { SIGN_IN_INIT_INFO } from "@/constants/signInput_constant";
+import { loginAccount } from "@/utils/api";
+import { useRouter } from "next/router";
import SignInput from "@/components/SignInput";
-import Image from "next/image";
+import errorMessage from '@/constants/error_messages';
import Link from "next/link";
import styles from '@/styles/SignPage.module.css';
-import linkbraryLogo from '@/public/images/logo.svg';
-import googleIcon from '@/public/images/Icon_Google.svg';
-import kakaoIcon from '@/public/images/Icon_Kakao2.svg';
-import errorMessage from '@/constants/error_messages';
-import { loginAccount } from "@/utils/api";
+import LinkbraryLogo from '@/public/images/logo.svg';
+import GoogleIcon from '@/public/images/Icon_Google.svg';
+import KakaoIcon from '@/public/images/Icon_Kakao2.svg';
+
+const ACCESS_TOKEN_KEY = 'accessToken';
export default function SignIn() {
const [emailErrorMsg, setEmailErrorMsg] = useState('');
const [pwErrorMsg, setPWErrorMsg] = useState('');
const [emailInputValue, setEmailInputValue] = useState('');
const [pwInputValue, setPWInputValue] = useState('');
+ const { email, password } = SIGN_IN_INIT_INFO;
const router = useRouter();
- const { email, password } = SIGNIN;
const handleEmailBlur = () => {
setEmailErrorMsg(validEmailInput(emailInputValue));
@@ -34,17 +35,11 @@ export default function SignIn() {
const handleSubmit = async(e: KeyboardEvent) => {
e.preventDefault();
- const userInfo = {
- "email": emailInputValue,
- "password": pwInputValue,
- }
-
- const res = await loginAccount(userInfo);
- const { data } = await res.json();
+ const res = await loginAccount(emailInputValue, pwInputValue);
- if (res.status === 200) {
- const accessToken = data?.accessToken;
- localStorage.setItem('accessToken', accessToken);
+ if (res.data) {
+ const accessToken = res.data?.accessToken;
+ localStorage.setItem(ACCESS_TOKEN_KEY, accessToken);
router.push('/folder')
}
@@ -53,18 +48,19 @@ export default function SignIn() {
}
useEffect(() => {
- // accessToken이 존재하면 folder로 이동
- const haveToken = localStorage.getItem('accessToken');
- if (haveToken) {
- router.push('/folder')
- }
- })
+ // accessToken이 존재하면 folder로 이동
+ const haveToken = localStorage.getItem(ACCESS_TOKEN_KEY);
+ if (haveToken) {
+ router.push('/folder')
+ }
+ return;
+ }, [router]);
return (
<>
-
+
회원이 아니신가요?
@@ -78,10 +74,10 @@ export default function SignIn() {
소셜로그인
-
+
-
+
diff --git a/pages/signup.tsx b/pages/signup.tsx
index 49ec9dd48..793c92808 100644
--- a/pages/signup.tsx
+++ b/pages/signup.tsx
@@ -1,14 +1,16 @@
-import { SIGNUP } from "@/constants/signInput_constant";
+import { validEmailInput, validPWCheckInput, validPasswordInput } from "@/utils/checkValid";
+import { SIGN_UP_INIT_INFO } from "@/constants/signInput_constant";
+import { ChangeEvent, KeyboardEvent, useState } from "react";
+import { addNewUser, checkAccount } from "@/utils/api";
+import { useRouter } from "next/router";
import SignInput from "@/components/SignInput";
-import Image from "next/image";
import Link from "next/link";
import styles from '@/styles/SignPage.module.css';
-import linkbraryLogo from '@/public/images/logo.svg';
-import googleIcon from '@/public/images/Icon_Google.svg';
-import kakaoIcon from '@/public/images/Icon_Kakao2.svg';
-import { ChangeEvent, useState } from "react";
-import { validEmailInput, validPWCheckInput, validPasswordInput } from "@/utils/checkValid";
+import LinkbraryLogo from '@/public/images/logo.svg';
+import GoogleIcon from '@/public/images/Icon_Google.svg';
+import KakaoIcon from '@/public/images/Icon_Kakao2.svg';
+const ACCESS_TOKEN_KEY = 'accessToken';
export default function SignUp() {
const [emailErrorMsg, setEmailErrorMsg] = useState('');
@@ -17,7 +19,8 @@ export default function SignUp() {
const [emailInputValue, setEmailInputValue] = useState('');
const [pwInputValue, setPWInputValue] = useState('');
const [pwCheckInputValue, setPWCheckInputValue] = useState('');
- const { email, password, pwCheck } = SIGNUP;
+ const { email, password, pwCheck } = SIGN_UP_INIT_INFO;
+ const router = useRouter();
const handleEmailBlur = () => {
setEmailErrorMsg(validEmailInput(emailInputValue));
@@ -34,17 +37,29 @@ export default function SignUp() {
if(e.target.id === "password-check") setPWCheckInputValue(e.target.value);
}
+ const handleSubmit = async(e: KeyboardEvent) => {
+ e.preventDefault();
+ const { error } = await checkAccount(emailInputValue);
+
+ if (error) return setEmailErrorMsg(error.message);
+
+ const { data } = await addNewUser(emailInputValue, pwInputValue);
+ const accessToken = data?.accessToken;
+ localStorage.setItem(ACCESS_TOKEN_KEY, accessToken);
+ router.push('/folder')
+ }
+
return (
<>
diff --git a/public/images/Icon_Google.svg b/public/images/Icon_Google.svg
index 0be07e8b1..9a42dc4d0 100644
--- a/public/images/Icon_Google.svg
+++ b/public/images/Icon_Google.svg
@@ -1,4 +1,4 @@
-
+
diff --git a/public/images/Icon_Kakao2.svg b/public/images/Icon_Kakao2.svg
index 4aa9f4525..87617d87e 100644
--- a/public/images/Icon_Kakao2.svg
+++ b/public/images/Icon_Kakao2.svg
@@ -1,4 +1,4 @@
-
+
diff --git a/public/images/logo.svg b/public/images/logo.svg
index 282022090..bbc2bd69a 100644
--- a/public/images/logo.svg
+++ b/public/images/logo.svg
@@ -1,4 +1,4 @@
-
+
diff --git a/styles/FolderList.module.css b/styles/FolderList.module.css
index 7e2e079e9..194738ea0 100644
--- a/styles/FolderList.module.css
+++ b/styles/FolderList.module.css
@@ -19,7 +19,7 @@
cursor: pointer;
}
-.addFolderBtn img {
+.addFolderBtnImg {
margin-left: 4px;
}
diff --git a/styles/FolderMenu.module.css b/styles/FolderMenu.module.css
index bf512d694..4613b958f 100644
--- a/styles/FolderMenu.module.css
+++ b/styles/FolderMenu.module.css
@@ -15,25 +15,12 @@
cursor: pointer;
}
-.shareBtn img {
+.folderMenuBtnImg {
width: 18px;
height: 18px;
margin-right: 4px;
}
-.editBtn img {
- width: 18px;
- height: 18px;
- margin-right: 4px;
-}
-
-.deleteBtn img {
- width: 18px;
- height: 18px;
- margin-right: 4px;
-}
-
-
/* mobile-size */
@media (max-width: 767px) {
.shareBtn, .editBtn, .deleteBtn {
diff --git a/styles/Footer.module.css b/styles/Footer.module.css
index 41386b9a0..20241b92e 100644
--- a/styles/Footer.module.css
+++ b/styles/Footer.module.css
@@ -29,7 +29,7 @@
text-decoration: none;
}
-.snsLinks img {
+.snsLinkImg {
margin-left: 8px;
}
diff --git a/styles/Header.module.css b/styles/Header.module.css
index 05e8620d5..339ff30f8 100644
--- a/styles/Header.module.css
+++ b/styles/Header.module.css
@@ -7,8 +7,9 @@
padding: 20px 0 60px;
}
-.headerItems img {
- width: 64px;
+.headerItemImg {
+ border-radius: 50%;
+ border: 2px solid var(--gray20);
}
.username {
diff --git a/styles/SignPage.module.css b/styles/SignPage.module.css
index 626fd4a38..8b3029a6b 100644
--- a/styles/SignPage.module.css
+++ b/styles/SignPage.module.css
@@ -49,7 +49,7 @@
margin: 32px auto;
}
-.snsLinkButtons img{
+.snsLinkButtonImg {
width: 42px;
margin-left: 16px;
}
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index 4ae479ba4..830304471 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -26,6 +26,7 @@
"custom.d.ts",
"**/*.ts",
"**/*.tsx",
+ "next.config.js",
"styles",
"pages",
"public"
diff --git a/types/type.ts b/types/type.ts
index 40192387b..54234febf 100644
--- a/types/type.ts
+++ b/types/type.ts
@@ -1,8 +1,8 @@
export interface LinkCardData {
url: string;
id: number;
- imageSource?: string;
- createdAt: string;
+ image_source?: string;
+ created_at: string;
description: string;
}
diff --git a/utils/api.ts b/utils/api.ts
index 26c644ee0..971eb859b 100644
--- a/utils/api.ts
+++ b/utils/api.ts
@@ -1,9 +1,8 @@
const BASE_URL = 'https://bootcamp-api.codeit.kr/api'
-const SHARED_USER_INFO_URL = `${BASE_URL}/sample/user`;
-const FOLDER_USER_INFO_URL = `${BASE_URL}/users/1`;
-const SHARED_DATA_API_URL = `${BASE_URL}/sample/folder`;
-const FOLDER_LIST_API_URL = `${BASE_URL}/users/1/folders`;
+const USER_INFO_URL = `${BASE_URL}/users`;
+const SHARED_DATA_API_URL = `${BASE_URL}/folders`;
+const FOLDER_All_DATA_API_URL = `${BASE_URL}/links`;
const FOLDER_DATA_API_URL = `${BASE_URL}/users/1/links?folderId=`;
async function getApi(url: string) {
@@ -16,48 +15,100 @@ async function getApi(url: string) {
return body;
}
-//shared 페이지 유저 데이터 조회
-export function getSampleUserInfo() {
- return getApi(SHARED_USER_INFO_URL);
+//페이지 유저 데이터 조회
+export async function getUserInfo() {
+ const accessToken = localStorage.getItem('accessToken');
+ const response = await fetch(USER_INFO_URL, {
+ method: 'GET',
+ headers: {
+ "Authorization": `Bearer ${accessToken}`
+ }
+ });
+
+ if (!response?.ok) {
+ throw new Error("정보를 불러오는데 실패했습니다.")
+ }
+
+ const body = await response.json();
+ return body;
+}
+
+//shared 페이지 폴더 소유자 데이터 조회
+export function getSharedFolderOwner(id: number) {
+ return getApi(`${USER_INFO_URL}/${id}`);
}
//shared 페이지 폴더 데이터 조회
-export function getSampleFolderLinks() {
- return getApi(SHARED_DATA_API_URL);
+export function getSharedFolderInfo(folderId: string | string[] | undefined) {
+ return getApi(`${SHARED_DATA_API_URL}/${folderId}`);
}
-//folder 페이지 유저 데이터 조회
-export function getFolderUserInfo() {
- return getApi(FOLDER_USER_INFO_URL);
+//shared 페이지 폴더의 링크 데이터 조회
+export function getSharedFolderLinks(userId: number, folderId: string | string[] | undefined) {
+ const query = `/${userId}/links?folderId=${folderId}`
+ return getApi(USER_INFO_URL + query);
}
//folder 페이지 폴더 데이터목록 조회
-export function getFolderLists() {
- return getApi(FOLDER_LIST_API_URL);
+export async function getFolderLists() {
+ const accessToken = localStorage.getItem('accessToken');
+ const response = await fetch(SHARED_DATA_API_URL, {
+ method: 'GET',
+ headers: {
+ "Authorization": `Bearer ${accessToken}`
+ }
+ });
+
+ if (!response?.ok) {
+ throw new Error("정보를 불러오는데 실패했습니다.")
+ }
+
+ const body = await response.json();
+ return body;
+}
+
+//folder 페이지 전체 폴더에 저장된 링크 데이터조회
+export async function getAllLinksData() {
+ const accessToken = localStorage.getItem('accessToken');
+ const response = await fetch(FOLDER_All_DATA_API_URL, {
+ method: 'GET',
+ headers: {
+ "Authorization": `Bearer ${accessToken}`
+ }
+ });
+
+ if (!response?.ok) {
+ throw new Error("정보를 불러오는데 실패했습니다.")
+ }
+
+ const body = await response.json();
+ return body;
}
//folder 페이지 폴더에 저장된 링크 데이터조회
-export function getFolderLinksData(id: number|string) {
+export function getFolderLinksData(id: string | string[] | undefined) {
const path = FOLDER_DATA_API_URL + id;
return getApi(path);
}
//로그인 API
-export async function loginAccount(userInfo: any) {
+export async function loginAccount(email: string, password: string) {
const res = await fetch (`${BASE_URL}/sign-in`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
- body: JSON.stringify(userInfo),
+ body: JSON.stringify({"email": email, "password": password}),
});
-
- return res;
+
+ const body = await res.json();
+
+ return body;
}
-//회원가입 API
-export async function addNewAccount(email: string, password: string) {
- const response = await fetch('https://bootcamp-api.codeit.kr/api/check-email', {
+//회원가입 전 이메일 중복체크
+export async function checkAccount(email: string) {
+ const res = await fetch(`${BASE_URL}/check-email`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
@@ -65,21 +116,22 @@ export async function addNewAccount(email: string, password: string) {
body: JSON.stringify({"email": email}),
});
- if (response.status === 200) {
- const newAccount = {
- "email": email,
- "password": password,
- }
-
- const response = await fetch('https://bootcamp-api.codeit.kr/api/sign-up', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(newAccount),
- });
- const result = await response.json();
- const accessToken = result.data?.loginUser.accessToken;
- localStorage.setItem('accessToken', accessToken);
- }
+ const body = await res.json();
+
+ return body;
+}
+
+//회원가입 API
+export async function addNewUser(email: string, password: string) {
+ const res = await fetch(`${BASE_URL}/sign-up`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({"email": email, "password": password}),
+ });
+
+ const body = await res.json();
+
+ return body;
}
\ No newline at end of file