From 51cac92f4c81e45a36cbbd45aa7d61178a405ae9 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 3 Oct 2023 17:32:44 +0800 Subject: [PATCH] chore: use prisma to create user id --- ...-adapter-prisma-npm-3.0.2-8cf3dc1a10.patch | 28 +++++++++++++++ .../patches/lucia-npm-2.7.1-781ace4b5e.patch | 35 +++++++++++++++++++ package.json | 4 ++- server/database/schema.prisma | 2 +- server/database/seed.ts | 2 +- 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 .yarn/patches/@lucia-auth-adapter-prisma-npm-3.0.2-8cf3dc1a10.patch create mode 100644 .yarn/patches/lucia-npm-2.7.1-781ace4b5e.patch diff --git a/.yarn/patches/@lucia-auth-adapter-prisma-npm-3.0.2-8cf3dc1a10.patch b/.yarn/patches/@lucia-auth-adapter-prisma-npm-3.0.2-8cf3dc1a10.patch new file mode 100644 index 000000000..7f2c892f9 --- /dev/null +++ b/.yarn/patches/@lucia-auth-adapter-prisma-npm-3.0.2-8cf3dc1a10.patch @@ -0,0 +1,28 @@ +diff --git a/dist/prisma.js b/dist/prisma.js +index 64924ab08a2fb22e6365a60c37adf684ea7ecbce..922babc0285618c8f737d6a3893dfe74e6ad962b 100644 +--- a/dist/prisma.js ++++ b/dist/prisma.js +@@ -33,14 +33,15 @@ export const prismaAdapter = (client, modelNames) => { + return; + } + try { +- await client.$transaction([ +- User.create({ +- data: user +- }), +- Key.create({ +- data: key +- }) +- ]); ++ // CHANGED: Use prisma nested create to create key ++ // Userid is taken care of by prisma automatically ++ const { user_id: _, ...keyData } = key; ++ await User.create({ ++ data: { ++ keys: { create: [keyData] }, ++ ...user ++ } ++ }); + } + catch (e) { + const error = e; diff --git a/.yarn/patches/lucia-npm-2.7.1-781ace4b5e.patch b/.yarn/patches/lucia-npm-2.7.1-781ace4b5e.patch new file mode 100644 index 000000000..c0cb71101 --- /dev/null +++ b/.yarn/patches/lucia-npm-2.7.1-781ace4b5e.patch @@ -0,0 +1,35 @@ +diff --git a/dist/auth/index.js b/dist/auth/index.js +index 8a70113bbb245dae9190f3392538e18afc750e52..377025c76a182e53113d9b8b12876bb5a405c0a7 100644 +--- a/dist/auth/index.js ++++ b/dist/auth/index.js +@@ -158,11 +158,12 @@ export class Auth { + return user; + }; + createUser = async (options) => { +- const userId = options.userId ?? generateRandomString(15); ++ // CHANGED: We want the db to generate the id ++ //const userId = options.userId ?? generateRandomString(15); + const userAttributes = options.attributes ?? {}; + const databaseUser = { + ...userAttributes, +- id: userId ++ //id: userId + }; + if (options.key === null) { + await this.adapter.setUser(databaseUser, null); +@@ -171,12 +172,11 @@ export class Auth { + const keyId = createKeyId(options.key.providerId, options.key.providerUserId); + const password = options.key.password; + const hashedPassword = password === null ? null : await this.passwordHash.generate(password); +- await this.adapter.setUser(databaseUser, { ++ return this.transformDatabaseUser(await this.adapter.setUser(databaseUser, { + id: keyId, +- user_id: userId, ++ //user_id: userId, + hashed_password: hashedPassword +- }); +- return this.transformDatabaseUser(databaseUser); ++ })); + }; + updateUserAttributes = async (userId, attributes) => { + await this.adapter.updateUser(userId, attributes); diff --git a/package.json b/package.json index 84901c06e..6597a69e6 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,9 @@ "mount-vue-component": "patch:mount-vue-component@npm%3A0.10.2#./.yarn/patches/mount-vue-component-npm-0.10.2-4968f76fd9.patch", "@vue/apollo-util": "patch:@vue/apollo-util@npm%3A4.0.0-beta.6#./.yarn/patches/@vue-apollo-util-npm-4.0.0-beta.6-7e26e14eb7.patch", "ioredis@^5.3.2": "patch:ioredis@npm%3A5.3.2#./.yarn/patches/ioredis-npm-5.3.2-58471071b1.patch", - "nitropack@^2.6.3": "patch:nitropack@npm%3A2.6.3#./.yarn/patches/nitropack-npm-2.6.3-72f7352600.patch" + "nitropack@^2.6.3": "patch:nitropack@npm%3A2.6.3#./.yarn/patches/nitropack-npm-2.6.3-72f7352600.patch", + "lucia@^2.7.1": "patch:lucia@npm%3A2.7.1#./.yarn/patches/lucia-npm-2.7.1-781ace4b5e.patch", + "@lucia-auth/adapter-prisma@^3.0.2": "patch:@lucia-auth/adapter-prisma@npm%3A3.0.2#./.yarn/patches/@lucia-auth-adapter-prisma-npm-3.0.2-8cf3dc1a10.patch" }, "resolutionsComments": { "@types/react": "Otherwise these types interfere with the types from vite: https://github.com/johnsoncodehk/volar/discussions/592#discussioncomment-1580518" diff --git a/server/database/schema.prisma b/server/database/schema.prisma index a3320f1cb..8ffacc382 100644 --- a/server/database/schema.prisma +++ b/server/database/schema.prisma @@ -17,7 +17,7 @@ model User { createdAt DateTime @default(now()) documents UserDocument[] groups Group[] - key Key[] // TODO: Rename to keys + keys Key[] } model Key { diff --git a/server/database/seed.ts b/server/database/seed.ts index d63985f6c..959ae670e 100644 --- a/server/database/seed.ts +++ b/server/database/seed.ts @@ -18,7 +18,7 @@ async function seedInternal(prisma: PrismaClientT): Promise { id: 'ckn4oul7100004cv7y3t94n8j', email: 'alice@jabref.org', name: 'Alice', - key: { + keys: { create: [ { id: 'email:alice@jabref.org',