From 47cc71fa6b72d9afd757d16adaa98e2fe1a662b5 Mon Sep 17 00:00:00 2001 From: KangJi Date: Thu, 14 Jan 2021 01:16:42 +0900 Subject: [PATCH] =?UTF-8?q?[Change]=20user=20=EA=B0=9D=EC=B2=B4=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/auth/index.js | 24 +++++++++++++----------- helpers/auth/index.js | 31 ++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/api/auth/index.js b/api/auth/index.js index 9b65f2c..5f6ace5 100644 --- a/api/auth/index.js +++ b/api/auth/index.js @@ -10,19 +10,17 @@ const postSignInFailResponseData = { signIn: false, }; -export const postSignIn = (userId, userPw) => { - if (userId === 'admin' && userPw === '1234') { - return fetch.post( - `fakeFetch.com/signin`, - { userId, userPw }, - postSignInSuccessResponseData, - ); +export const postSignIn = aUser => { + let res = postSignInFailResponseData; + + if (aUser.userId === 'admin' && aUser.userPw === '1234') { + res = postSignInSuccessResponseData; } return fetch.post( `fakeFetch.com/signin`, - { userId, userPw }, - postSignInFailResponseData, + { userId: aUser.userId, userPw: aUser.userPw }, + res, ); }; @@ -31,6 +29,10 @@ const postSignOutSuccessResponseData = { signOut: true, }; -export const postSignOut = () => { - return fetch.post(`fakeFetch.com/signout`, postSignOutSuccessResponseData); +export const postSignOut = aUser => { + return fetch.post( + `fakeFetch.com/signout`, + { userId: aUser.userId }, + postSignOutSuccessResponseData, + ); }; diff --git a/helpers/auth/index.js b/helpers/auth/index.js index c201b53..3d69d09 100644 --- a/helpers/auth/index.js +++ b/helpers/auth/index.js @@ -1,26 +1,35 @@ import * as authApi from '../../api/auth'; +import User from '../../objects/User'; + let stateSignIn = false; -let userId = ''; +let user = new User(); + +const initState = () => { + stateSignIn = false; + user = new User(); +}; + +const setState = aUser => { + stateSignIn = true; + user = aUser; +}; export const signIn = async (intputUserId, inputUserPw) => { - const response = await authApi.postSignIn(intputUserId, inputUserPw); + // 암호화 필요 + const cryptoPw = inputUserPw; + const inputUser = new User({ userId: intputUserId, userPw: cryptoPw }); + const response = await authApi.postSignIn(inputUser); - if (response.signIn) { - stateSignIn = true; - userId = intputUserId; - } + if (response.signIn) setState(); return stateSignIn; }; export const signOut = async () => { - const response = await authApi.postSignIn(userId); + const response = await authApi.postSignIn(user); - if (response.signOut) { - stateSignIn = false; - userId = ''; - } + if (response.signOut) initState(); return !stateSignIn; };