Skip to content

Commit 374d2f8

Browse files
authored
Merge pull request #116 from umc-commit/bug/social-login
[BUG] 소셜 로그인 버그 수정
2 parents b762e3a + b2af5a0 commit 374d2f8

File tree

10 files changed

+367
-130
lines changed

10 files changed

+367
-130
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `user_id` on the `user_agreement` table. All the data in the column will be lost.
5+
- The primary key for the `user_categories` table will be changed. If it partially fails, the table could be left without primary key constraint.
6+
- You are about to drop the column `user_id` on the `user_categories` table. All the data in the column will be lost.
7+
- A unique constraint covering the columns `[account_id,agreement_id]` on the table `user_agreement` will be added. If there are existing duplicate values, this will fail.
8+
- Added the required column `account_id` to the `user_agreement` table without a default value. This is not possible if the table is not empty.
9+
- Added the required column `account_id` to the `user_categories` table without a default value. This is not possible if the table is not empty.
10+
11+
*/
12+
-- DropForeignKey
13+
ALTER TABLE `user_agreement` DROP FOREIGN KEY `user_agreement_user_id_fkey`;
14+
15+
-- DropForeignKey
16+
ALTER TABLE `user_categories` DROP FOREIGN KEY `user_categories_user_id_fkey`;
17+
18+
-- DropIndex
19+
DROP INDEX `user_agreement_user_id_agreement_id_key` ON `user_agreement`;
20+
21+
-- AlterTable
22+
ALTER TABLE `user_agreement` DROP COLUMN `user_id`,
23+
ADD COLUMN `account_id` BIGINT NOT NULL;
24+
25+
-- AlterTable
26+
ALTER TABLE `user_categories` DROP PRIMARY KEY,
27+
DROP COLUMN `user_id`,
28+
ADD COLUMN `account_id` BIGINT NOT NULL,
29+
ADD PRIMARY KEY (`account_id`, `category_id`);
30+
31+
-- CreateIndex
32+
CREATE UNIQUE INDEX `user_agreement_account_id_agreement_id_key` ON `user_agreement`(`account_id`, `agreement_id`);
33+
34+
-- AddForeignKey
35+
ALTER TABLE `user_categories` ADD CONSTRAINT `user_categories_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
36+
37+
-- AddForeignKey
38+
ALTER TABLE `user_agreement` ADD CONSTRAINT `user_agreement_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[account_id]` on the table `artists` will be added. If there are existing duplicate values, this will fail.
5+
- A unique constraint covering the columns `[account_id]` on the table `users` will be added. If there are existing duplicate values, this will fail.
6+
7+
*/
8+
-- CreateIndex
9+
CREATE UNIQUE INDEX `artists_account_id_key` ON `artists`(`account_id`);
10+
11+
-- CreateIndex
12+
CREATE UNIQUE INDEX `users_account_id_key` ON `users`(`account_id`);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `user_id` on the `follows` table. All the data in the column will be lost.
5+
- A unique constraint covering the columns `[account_id,artist_id]` on the table `follows` will be added. If there are existing duplicate values, this will fail.
6+
- Added the required column `account_id` to the `follows` table without a default value. This is not possible if the table is not empty.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE `follows` DROP FOREIGN KEY `follows_user_id_fkey`;
11+
12+
-- DropIndex
13+
DROP INDEX `follows_user_id_artist_id_key` ON `follows`;
14+
15+
-- AlterTable
16+
ALTER TABLE `follows` DROP COLUMN `user_id`,
17+
ADD COLUMN `account_id` BIGINT NOT NULL;
18+
19+
-- CreateIndex
20+
CREATE UNIQUE INDEX `follows_account_id_artist_id_key` ON `follows`(`account_id`, `artist_id`);
21+
22+
-- AddForeignKey
23+
ALTER TABLE `follows` ADD CONSTRAINT `follows_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ model Account {
1919
oauthId String @map("oauth_id") @db.VarChar(255)
2020
createdAt DateTime @default(now()) @map("created_at")
2121
22-
users User[]
23-
artists Artist[]
22+
users User[]
23+
artists Artist[]
24+
userAgreements UserAgreement[]
25+
userCategories UserCategory[]
26+
follows Follow[]
2427
2528
@@unique([provider, oauthId])
2629
@@map("accounts")
@@ -29,7 +32,7 @@ model Account {
2932
model User {
3033
id BigInt @id @default(autoincrement())
3134
nickname String @db.VarChar(50)
32-
accountId BigInt @map("account_id")
35+
accountId BigInt @map("account_id") @unique
3336
description String? @db.VarChar(1000)
3437
profileImage String? @map("profile_image") @db.VarChar(255)
3538
createdAt DateTime @default(now()) @map("created_at")
@@ -44,10 +47,7 @@ model User {
4447
chatMessages ChatMessage[]
4548
reviews Review[]
4649
bookmarks Bookmark[]
47-
follows Follow[]
4850
notifications Notification[]
49-
userAgreements UserAgreement[]
50-
userCategories UserCategory[]
5151
searchHistories SearchHistory[]
5252
pushToken PushToken?
5353
@@ -56,7 +56,7 @@ model User {
5656

5757
model Artist {
5858
id BigInt @id @default(autoincrement())
59-
accountId BigInt @map("account_id")
59+
accountId BigInt @map("account_id") @unique
6060
nickname String @db.VarChar(50)
6161
profileImage String? @map("profile_image") @db.VarChar(255)
6262
description String? @db.VarChar(1000)
@@ -83,13 +83,13 @@ model Category {
8383
}
8484

8585
model UserCategory {
86-
userId BigInt @map("user_id")
86+
accountId BigInt @map("account_id")
8787
categoryId BigInt @map("category_id")
8888
89-
user User @relation(fields: [userId], references: [id])
89+
account Account @relation(fields: [accountId], references: [id])
9090
category Category @relation(fields: [categoryId], references: [id])
9191
92-
@@id([userId, categoryId])
92+
@@id([accountId, categoryId])
9393
@@map("user_categories")
9494
}
9595

@@ -241,13 +241,13 @@ model ChatMessage {
241241
model Follow {
242242
id BigInt @id @default(autoincrement())
243243
artistId BigInt @map("artist_id")
244-
userId BigInt @map("user_id")
244+
accountId BigInt @map("account_id")
245245
createdAt DateTime @default(now()) @map("created_at")
246246
247-
artist Artist @relation(fields: [artistId], references: [id])
248-
user User @relation(fields: [userId], references: [id])
247+
artist Artist @relation(fields: [artistId], references: [id])
248+
account Account @relation(fields: [accountId], references: [id])
249249
250-
@@unique([userId, artistId])
250+
@@unique([accountId, artistId])
251251
@@map("follows")
252252
}
253253

@@ -337,13 +337,13 @@ model Agreement {
337337

338338
model UserAgreement {
339339
id BigInt @id @default(autoincrement())
340-
userId BigInt @map("user_id")
340+
accountId BigInt @map("account_id")
341341
agreementId BigInt @map("agreement_id")
342342
343-
user User @relation(fields: [userId], references: [id])
343+
account Account @relation(fields: [accountId], references: [id])
344344
agreement Agreement @relation(fields: [agreementId], references: [id])
345345
346-
@@unique([userId, agreementId])
346+
@@unique([accountId, agreementId])
347347
@@map("user_agreement")
348348
}
349349

prisma/seed.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,89 @@ async function main() {
5555
});
5656

5757
// Category 생성
58-
const category = await prisma.category.create({
58+
const category1 = await prisma.category.create({
5959
data: {
60-
name: "캐릭터 일러스트",
60+
name: "글",
61+
},
62+
});
63+
// Category 생성
64+
const category2 = await prisma.category.create({
65+
data: {
66+
name: "그림",
67+
},
68+
});
69+
// Category 생성
70+
const category3 = await prisma.category.create({
71+
data: {
72+
name: "영상",
73+
},
74+
});
75+
// Category 생성
76+
const category4 = await prisma.category.create({
77+
data: {
78+
name: "디자인",
79+
},
80+
});
81+
// Category 생성
82+
const category5 = await prisma.category.create({
83+
data: {
84+
name: "굿즈",
85+
},
86+
});
87+
// Category 생성
88+
const category6 = await prisma.category.create({
89+
data: {
90+
name: "점술",
91+
},
92+
});
93+
// Category 생성
94+
const category7 = await prisma.category.create({
95+
data: {
96+
name: "사운드",
97+
},
98+
});
99+
// Category 생성
100+
const category8 = await prisma.category.create({
101+
data: {
102+
name: "모션",
103+
},
104+
});
105+
// Category 생성
106+
const category9 = await prisma.category.create({
107+
data: {
108+
name: "외주",
109+
},
110+
});
111+
112+
// Agreements 생성
113+
const agreement1 = await prisma.agreement.create({
114+
data: {
115+
agreeType:"(필수) 서비스 이용약관"
116+
},
117+
});
118+
// Agreements 생성
119+
const agreement2 = await prisma.agreement.create({
120+
data: {
121+
agreeType:"(필수) 개인정보 수집/이용 동의"
122+
},
123+
});
124+
// Agreements 생성
125+
const agreement3 = await prisma.agreement.create({
126+
data: {
127+
agreeType:"(선택) 마케팅 수신 동의"
61128
},
62129
});
63130

64131
// Commission 생성 (Artist가 작성)
65132
const commission = await prisma.commission.create({
66133
data: {
67134
artistId: artist.id,
68-
categoryId: category.id,
135+
categoryId: 1,
69136
title: "테스트 커미션 글",
70137
summary: "이것은 테스트용 커미션 글입니다.",
71138
content: "테스트 커미션의 상세 설명입니다. 이 부분에는 커미션의 자세한 내용이 들어갑니다.",
72139
minPrice: 1000,
140+
73141
formSchema: {},
74142
},
75143
});

src/auth.config.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ export const googleStrategy = new GoogleStrategy(
2424

2525
const googleVerify = async (profile) => {
2626

27+
console.log("profile -> ",profile);
28+
2729
const user = await prisma.account.findFirst({
2830
where: {oauthId : profile.id, provider:profile.provider},
29-
include:{users:true},
31+
include:{users:true, artists:true},
3032
});
3133

32-
if (user !== null) {
33-
return { id: user.users[0].id, nickname: user.users[0].nickname, account_id : user.id.toString() };
34+
console.log("user -> ", user);
35+
36+
if (user && user.users.length>0) {
37+
return { id: user.users[0].id, nickname: user.users[0].nickname, accountId : user.id.toString(), userId: user.users[0].id.toString(), role:'client', provider: user.provider, oauthId:user.oauthId };
38+
}
39+
40+
if(user && user.artists.length>0){
41+
return{id:user.artists[0].id, nickname:user.artists[0].nickname, accountId:user.id.toString(), artistId: user.artists[0].id.toString(), role:'artist', provider:user.provider, oauthId: user.oauthId};
3442
}
3543

3644
// 사용자가 없으면 회원가입 페이지로 이동하도록 응답
@@ -59,21 +67,29 @@ export const kakaoStrategy = new KakaoStrategy(
5967

6068
const kakaoVerify = async (profile) => {
6169

70+
console.log(profile);
71+
6272
const user = await prisma.account.findFirst({
6373
where: {oauthId : profile.id.toString(), provider:profile.provider},
64-
include:{users:true},
74+
include:{users:true, artists:true},
6575
});
6676

67-
if (user !== null) {
68-
return { id: user.users[0].id, nickname: user.users[0].nickname, account_id : user.id.toString() };
77+
console.log(user);
78+
79+
if (user && user.users.length>0) {
80+
return { id: user.users[0].id, nickname: user.users[0].nickname, accountId : user.id.toString(), userId: user.users[0].id.toString(), role:'client', provider: user.provider, oauthId:user.oauthId };
81+
}
82+
83+
if(user && user.artists.length>0){
84+
return{id:user.artists[0].id, nickname:user.artists[0].nickname, accountId:user.id.toString(), artistId: user.artists[0].id.toString(), role:'artist', provider:user.provider, oauthId: user.oauthId};
6985
}
7086

7187
// 사용자가 없으면 회원가입 페이지로 이동하도록 응답
7288
// ex. 프론트에서 signupRequired : true를 응답받으면 회원가입 페이지로 이동
7389
return {
7490
signupRequired : true,
7591
provider : profile.provider,
76-
oauth_id : profile.id,
92+
oauth_id : profile.id.toString(),
7793
};
7894
};
7995

@@ -94,14 +110,20 @@ export const naverStrategy = new NaverStrategy(
94110
);
95111

96112
const naverVerify = async (profile) => {
97-
113+
98114
const user = await prisma.account.findFirst({
99115
where: {oauthId : profile.id.toString(), provider:profile.provider},
100-
include:{users:true},
116+
include:{users:true, artists:true},
101117
});
102118

103-
if (user !== null) {
104-
return { id: user.users[0].id, nickname: user.users[0].nickname, account_id : user.id.toString() };
119+
console.log(user);
120+
121+
if (user && user.users.length>0) {
122+
return { id: user.users[0].id, nickname: user.users[0].nickname, accountId : user.id.toString(), userId: user.users[0].id.toString(), role:'client', provider: user.provider, oauthId:user.oauthId };
123+
}
124+
125+
if(user && user.artists.length>0){
126+
return{id:user.artists[0].id, nickname:user.artists[0].nickname, accountId:user.id.toString(), artistId: user.artists[0].id.toString(), role:'artist', provider:user.provider, oauthId: user.oauthId};
105127
}
106128

107129
// 사용자가 없으면 회원가입 페이지로 이동하도록 응답

0 commit comments

Comments
 (0)