Skip to content

Commit

Permalink
fix: email verification in mikro-orm adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Nov 15, 2023
1 parent 2065354 commit f67254b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@
"node": ">= 16.0.0",
"yarn": ">=3.2.0"
},
"packageManager": "[email protected].1"
"packageManager": "[email protected].2"
}
2 changes: 2 additions & 0 deletions packages/database-mikro-orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 16 additions & 1 deletion packages/database-mikro-orm/src/mikro-orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,20 @@ const toUser = async (user: IUser<any, any, any> | null): Promise<AccountsUser |
...user,
id: String(user.id),
emails: await user.emails.loadItems(),
services: (await user.services.loadItems()).reduce(
(acc, { name, token, options }: { name: string; token?: string; options?: object }) => {
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<any> | null): Promise<ISession | null> =>
Expand Down Expand Up @@ -133,7 +148,7 @@ export class AccountsMikroOrm<
return toUser(
await this.userRepository.findOne({
services: {
name: 'password.verificationTokens',
name: 'email.verificationTokens',
token,
},
})
Expand Down
6 changes: 5 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f67254b

Please sign in to comment.