From 394ef50f4dfffa35144f439bed5b7d315c6d24f3 Mon Sep 17 00:00:00 2001 From: rnjshippo Date: Thu, 17 Dec 2020 18:01:54 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20OAuth=20user=20image=EC=9E=88?= =?UTF-8?q?=EC=9C=BC=EB=A9=B4=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/api/index.ts | 2 +- server/src/models/user.model.ts | 14 +++++++++++++- server/src/routes/api/oauth/oauth.controller.ts | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/client/src/api/index.ts b/client/src/api/index.ts index b259caba..20ab36b5 100644 --- a/client/src/api/index.ts +++ b/client/src/api/index.ts @@ -57,7 +57,7 @@ instance.interceptors.response.use( if (axios.isCancel(err)) { console.log('요청 취소', err); } else { - if (err.response.status === 401) { + if (err?.response?.status === 401) { const { url } = err.response.config; if (url !== '/api/auth/login' && url !== '/api/oauth/google/signup') { window.location.href = '/login'; diff --git a/server/src/models/user.model.ts b/server/src/models/user.model.ts index 1be56ed7..92f3717c 100644 --- a/server/src/models/user.model.ts +++ b/server/src/models/user.model.ts @@ -68,7 +68,19 @@ export const userModel = { const sql = `INSERT INTO user (email, pw, display_name) VALUES (?, ?, ?);`; return pool.execute(sql, [email, pw, displayName]); }, - addOAuthUser({ email, displayName }: { email: string; displayName: string }): any { + addOAuthUser({ + email, + displayName, + image, + }: { + email: string; + displayName: string; + image?: string; + }): any { + if (image) { + const sql = `INSERT INTO user (email, display_name, image) VALUES (?, ?, ?);`; + return pool.execute(sql, [email, displayName, image]); + } const sql = `INSERT INTO user (email, display_name) VALUES (?, ?);`; return pool.execute(sql, [email, displayName]); }, diff --git a/server/src/routes/api/oauth/oauth.controller.ts b/server/src/routes/api/oauth/oauth.controller.ts index 5552c95d..5c7af77e 100644 --- a/server/src/routes/api/oauth/oauth.controller.ts +++ b/server/src/routes/api/oauth/oauth.controller.ts @@ -59,7 +59,9 @@ export const googleSignup = async ( if (user) { userInfo = { email: user.email, displayName: user.displayName, id: user.id }; } else { - const [{ insertId }] = await userModel.addOAuthUser({ email, displayName: name }); + const [{ insertId }] = picture + ? await userModel.addOAuthUser({ email, displayName: name, image: picture }) + : await userModel.addOAuthUser({ email, displayName: name }); await channelModel.setUserChannel({ userId: insertId }); userInfo = { email, displayName: name, id: insertId }; } From 816b0ece04a7cf97c491bae97edc07695881bcfd Mon Sep 17 00:00:00 2001 From: rnjshippo Date: Thu, 17 Dec 2020 18:26:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[refactor]=20=EC=B1=84=EB=84=90=EC=9D=98=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=EC=97=90?= =?UTF-8?q?=EC=84=9C=20remove=EB=B2=84=ED=8A=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 안씀 --- .../ShowUsersModal/ShowUsersModalBody/ShowUsersModalBody.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/components/ThreadListBox/ThreadListHeader/ChannelModal/ShowUsersModal/ShowUsersModalBody/ShowUsersModalBody.tsx b/client/src/components/ThreadListBox/ThreadListHeader/ChannelModal/ShowUsersModal/ShowUsersModalBody/ShowUsersModalBody.tsx index 3bc30895..ca6d5640 100644 --- a/client/src/components/ThreadListBox/ThreadListHeader/ChannelModal/ShowUsersModal/ShowUsersModalBody/ShowUsersModalBody.tsx +++ b/client/src/components/ThreadListBox/ThreadListHeader/ChannelModal/ShowUsersModal/ShowUsersModalBody/ShowUsersModalBody.tsx @@ -66,7 +66,6 @@ const ShowUsersModalBody: React.FC = () => { {user.displayName} - Remove ))}