Skip to content

Commit

Permalink
Merge pull request #72 from DINTeam/feature/make_user_object
Browse files Browse the repository at this point in the history
[Feature] make user object
  • Loading branch information
KangJiJi authored Jan 13, 2021
2 parents 6bdbdd8 + 47cc71f commit 34fd2f1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
24 changes: 13 additions & 11 deletions api/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
};

Expand All @@ -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,
);
};
31 changes: 20 additions & 11 deletions helpers/auth/index.js
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down
17 changes: 17 additions & 0 deletions objects/User.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 34fd2f1

Please sign in to comment.