Skip to content

Commit f67254b

Browse files
committed
fix: email verification in mikro-orm adapter
1 parent 2065354 commit f67254b

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@
8888
"node": ">= 16.0.0",
8989
"yarn": ">=3.2.0"
9090
},
91-
"packageManager": "[email protected].1"
91+
"packageManager": "[email protected].2"
9292
}

packages/database-mikro-orm/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
"@mikro-orm/migrations": "6.0.0-dev.151",
3636
"@mikro-orm/postgresql": "6.0.0-dev.151",
3737
"@mikro-orm/reflection": "6.0.0-dev.151",
38+
"@types/lodash": "^4.14.201",
3839
"graphql": "16.8.1",
3940
"graphql-modules": "3.0.0-alpha-20231106133212-0b04b56e"
4041
},
4142
"dependencies": {
4243
"@accounts/types": "^0.33.2",
44+
"lodash": "^4.17.21",
4345
"tslib": "2.6.2"
4446
},
4547
"peerDependencies": {

packages/database-mikro-orm/src/mikro-orm.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { User as AccountsUser } from '@accounts/types/lib/types/user';
1515
import { Session as ISession } from '@accounts/types/lib/types/session/session';
1616
import { ExecutionContext, Inject, Injectable } from 'graphql-modules';
17+
import { get, set } from 'lodash';
1718

1819
const hasPassword = (opt: object): opt is { bcrypt: string } =>
1920
!!(opt as { bcrypt: string }).bcrypt;
@@ -23,6 +24,20 @@ const toUser = async (user: IUser<any, any, any> | null): Promise<AccountsUser |
2324
...user,
2425
id: String(user.id),
2526
emails: await user.emails.loadItems(),
27+
services: (await user.services.loadItems()).reduce(
28+
(acc, { name, token, options }: { name: string; token?: string; options?: object }) => {
29+
const multi = ['email.verificationTokens', 'password.reset'];
30+
set(
31+
acc,
32+
name,
33+
multi.includes(name)
34+
? (get(acc, name) ?? []).concat({ token, ...options })
35+
: { ...get(acc, name), token, ...options }
36+
);
37+
return acc;
38+
},
39+
{}
40+
),
2641
};
2742

2843
const toSession = async (session: Session<any> | null): Promise<ISession | null> =>
@@ -133,7 +148,7 @@ export class AccountsMikroOrm<
133148
return toUser(
134149
await this.userRepository.findOne({
135150
services: {
136-
name: 'password.verificationTokens',
151+
name: 'email.verificationTokens',
137152
token,
138153
},
139154
})

yarn.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ __metadata:
189189
"@mikro-orm/migrations": "npm:6.0.0-dev.151"
190190
"@mikro-orm/postgresql": "npm:6.0.0-dev.151"
191191
"@mikro-orm/reflection": "npm:6.0.0-dev.151"
192+
"@types/lodash": "npm:^4.14.201"
192193
graphql: "npm:16.8.1"
193194
graphql-modules: "npm:3.0.0-alpha-20231106133212-0b04b56e"
195+
lodash: "npm:^4.17.21"
194196
tslib: "npm:2.6.2"
195197
peerDependencies:
196198
"@mikro-orm/cli": ^6.0.0
@@ -591,6 +593,8 @@ __metadata:
591593
request-ip: "npm:3.3.0"
592594
tslib: "npm:2.6.2"
593595
peerDependencies:
596+
"@accounts/magic-link": ^0.1.0
597+
"@accounts/password": ^0.32.0
594598
"@accounts/server": ^0.32.0 || ^0.33.0
595599
languageName: unknown
596600
linkType: soft
@@ -8110,7 +8114,7 @@ __metadata:
81108114
languageName: node
81118115
linkType: hard
81128116

8113-
"@types/lodash@npm:*, @types/lodash@npm:4.14.201":
8117+
"@types/lodash@npm:*, @types/lodash@npm:4.14.201, @types/lodash@npm:^4.14.201":
81148118
version: 4.14.201
81158119
resolution: "@types/lodash@npm:4.14.201"
81168120
checksum: 14dc43787296c429433d7d034ed47c5ac24b92217056f80a0e6c990449120b9c9c1058918188945fb88353c0c8333c5c36dccc40c51edbd39b05d2169ab2e0ad

0 commit comments

Comments
 (0)