Skip to content

Commit

Permalink
[be] refactor (#95) 로그인 뮤테이션 리팩토링
Browse files Browse the repository at this point in the history
- 로그인 arg.를 info 객체로 받음
  • Loading branch information
ahnsoheee committed Dec 13, 2020
1 parent 416a21c commit 0d6dcb9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/graphql/resolver/mutations/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export default {
return SIGNUP_ERROR;
}
},
signin: async (_, { type, id, password }, { dataSources, res }) => {
signin: async (_, { info }, { dataSources, res }) => {
try {
const schema = type === 'user' ? dataSources.model('User') : dataSources.model('Driver');
const result = await schema.findOne({ id });
const schema = info.type === 'user' ? dataSources.model('User') : dataSources.model('Driver');
const result = await schema.findOne({ id: info.id });
if (result) {
if (await bcrypt.compare(password, result.password)) {
if (await bcrypt.compare(info.password, result.password)) {
const token = jwt.sign({ id: result._id }, Config.JWT_SECRET);
res.cookie(`${type}Token`, token, { httpOnly: true, signed: true });
logger.info(`${id} ${type} logined!`);
res.cookie(`${info.type}Token`, token, { httpOnly: true, signed: true });
logger.info(`${info.id} ${info.type} logined!`);
return { success: true };
}
return { success: false, message: '잘못된 비밀번호입니다.' };
Expand Down

0 comments on commit 0d6dcb9

Please sign in to comment.