Skip to content

Commit

Permalink
Merge pull request #142 from rnjshippo/dev
Browse files Browse the repository at this point in the history
OAuth user image있으면 추가하도록 구현
  • Loading branch information
rnjshippo authored Dec 17, 2020
2 parents e5fc9ce + 816b0ec commit 1482b85
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const ShowUsersModalBody: React.FC = () => {
<SearchedUserBox key={user.userId}>
<ProfileImg src={user.image} />
<UserName>{user.displayName}</UserName>
<Remove>Remove</Remove>
</SearchedUserBox>
))}
</SearchedUserContainer>
Expand Down
14 changes: 13 additions & 1 deletion server/src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
},
Expand Down
4 changes: 3 additions & 1 deletion server/src/routes/api/oauth/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 1482b85

Please sign in to comment.