From f67254be8db2187631d7e768d72cf8bb8e5a546f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Belli?= Date: Wed, 15 Nov 2023 09:37:42 +0100 Subject: [PATCH] fix: email verification in mikro-orm adapter --- package.json | 2 +- packages/database-mikro-orm/package.json | 2 ++ packages/database-mikro-orm/src/mikro-orm.ts | 17 ++++++++++++++++- yarn.lock | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dd0d00541..1dc805939 100644 --- a/package.json +++ b/package.json @@ -88,5 +88,5 @@ "node": ">= 16.0.0", "yarn": ">=3.2.0" }, - "packageManager": "yarn@4.0.1" + "packageManager": "yarn@4.0.2" } diff --git a/packages/database-mikro-orm/package.json b/packages/database-mikro-orm/package.json index e3d49e967..87a8c52e0 100644 --- a/packages/database-mikro-orm/package.json +++ b/packages/database-mikro-orm/package.json @@ -35,11 +35,13 @@ "@mikro-orm/migrations": "6.0.0-dev.151", "@mikro-orm/postgresql": "6.0.0-dev.151", "@mikro-orm/reflection": "6.0.0-dev.151", + "@types/lodash": "^4.14.201", "graphql": "16.8.1", "graphql-modules": "3.0.0-alpha-20231106133212-0b04b56e" }, "dependencies": { "@accounts/types": "^0.33.2", + "lodash": "^4.17.21", "tslib": "2.6.2" }, "peerDependencies": { diff --git a/packages/database-mikro-orm/src/mikro-orm.ts b/packages/database-mikro-orm/src/mikro-orm.ts index b9570b810..909e3bfb8 100644 --- a/packages/database-mikro-orm/src/mikro-orm.ts +++ b/packages/database-mikro-orm/src/mikro-orm.ts @@ -14,6 +14,7 @@ import { import { User as AccountsUser } from '@accounts/types/lib/types/user'; import { Session as ISession } from '@accounts/types/lib/types/session/session'; import { ExecutionContext, Inject, Injectable } from 'graphql-modules'; +import { get, set } from 'lodash'; const hasPassword = (opt: object): opt is { bcrypt: string } => !!(opt as { bcrypt: string }).bcrypt; @@ -23,6 +24,20 @@ const toUser = async (user: IUser | null): Promise { + const multi = ['email.verificationTokens', 'password.reset']; + set( + acc, + name, + multi.includes(name) + ? (get(acc, name) ?? []).concat({ token, ...options }) + : { ...get(acc, name), token, ...options } + ); + return acc; + }, + {} + ), }; const toSession = async (session: Session | null): Promise => @@ -133,7 +148,7 @@ export class AccountsMikroOrm< return toUser( await this.userRepository.findOne({ services: { - name: 'password.verificationTokens', + name: 'email.verificationTokens', token, }, }) diff --git a/yarn.lock b/yarn.lock index 8d4075119..793fa99ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -189,8 +189,10 @@ __metadata: "@mikro-orm/migrations": "npm:6.0.0-dev.151" "@mikro-orm/postgresql": "npm:6.0.0-dev.151" "@mikro-orm/reflection": "npm:6.0.0-dev.151" + "@types/lodash": "npm:^4.14.201" graphql: "npm:16.8.1" graphql-modules: "npm:3.0.0-alpha-20231106133212-0b04b56e" + lodash: "npm:^4.17.21" tslib: "npm:2.6.2" peerDependencies: "@mikro-orm/cli": ^6.0.0 @@ -591,6 +593,8 @@ __metadata: request-ip: "npm:3.3.0" tslib: "npm:2.6.2" peerDependencies: + "@accounts/magic-link": ^0.1.0 + "@accounts/password": ^0.32.0 "@accounts/server": ^0.32.0 || ^0.33.0 languageName: unknown linkType: soft @@ -8110,7 +8114,7 @@ __metadata: languageName: node linkType: hard -"@types/lodash@npm:*, @types/lodash@npm:4.14.201": +"@types/lodash@npm:*, @types/lodash@npm:4.14.201, @types/lodash@npm:^4.14.201": version: 4.14.201 resolution: "@types/lodash@npm:4.14.201" checksum: 14dc43787296c429433d7d034ed47c5ac24b92217056f80a0e6c990449120b9c9c1058918188945fb88353c0c8333c5c36dccc40c51edbd39b05d2169ab2e0ad