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; }; diff --git a/objects/User.js b/objects/User.js new file mode 100644 index 0000000..1eef92a --- /dev/null +++ b/objects/User.js @@ -0,0 +1,17 @@ +class User { + constructor(aUser) { + if (!aUser) return; + this._userId = aUser.userId || ''; + this._userPw = aUser.userPw || ''; + } + + get userId() { + return this._userId; + } + + get userPw() { + return this._userPw; + } +} + +export default User;