Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use prisma to create user id #2258

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
35 changes: 35 additions & 0 deletions .yarn/patches/lucia-npm-2.7.1-781ace4b5e.patch
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion server/database/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ model User {
createdAt DateTime @default(now())
documents UserDocument[]
groups Group[]
key Key[] // TODO: Rename to keys
keys Key[]
}

model Key {
Expand Down
2 changes: 1 addition & 1 deletion server/database/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function seedInternal(prisma: PrismaClientT): Promise<void> {
id: 'ckn4oul7100004cv7y3t94n8j',
email: '[email protected]',
name: 'Alice',
key: {
keys: {
create: [
{
id: 'email:[email protected]',
Expand Down
Loading