Skip to content

Commit

Permalink
Merge a9e36df into 2450f33
Browse files Browse the repository at this point in the history
  • Loading branch information
blessanabraham authored Feb 5, 2021
2 parents 2450f33 + a9e36df commit 0802624
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
24 changes: 10 additions & 14 deletions packages/database-typeorm/__tests__/typeorm-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ describe('TypeormServicePassword', () => {
},
],
services: {
password: [
{
bcrypt: 'toto',
},
],
password: {
bcrypt: 'toto',
},
},
createdAt: expect.any(Date),
updatedAt: expect.any(Date),
Expand All @@ -81,12 +79,10 @@ describe('TypeormServicePassword', () => {
});
const ret = await accountsTypeorm.findUserById(userId);
expect(userId).toBeTruthy();
expect(ret!.services).toMatchObject({
password: [
{
bcrypt: 'toto',
},
],
expect(ret!.services).toEqual({
password: {
bcrypt: 'toto',
},
});
});

Expand Down Expand Up @@ -270,7 +266,7 @@ describe('TypeormServicePassword', () => {
const ret = await accountsTypeorm.findPasswordHash(userId);
const services: any = retUser!.services;
expect(ret).toBeTruthy();
expect(ret).toEqual(services.password[0].bcrypt);
expect(ret).toEqual(services.password.bcrypt);
});
});

Expand Down Expand Up @@ -409,8 +405,8 @@ describe('TypeormServicePassword', () => {
await accountsTypeorm.setPassword(userId, newPassword);
const retUser = await accountsTypeorm.findUserById(userId);
const services: any = retUser!.services;
expect(services.password[0].bcrypt).toBeTruthy();
expect(services.password[0].bcrypt).toEqual(newPassword);
expect(services.password.bcrypt).toBeTruthy();
expect(services.password.bcrypt).toEqual(newPassword);
expect(retUser!.createdAt).not.toEqual(retUser!.updatedAt);
});
});
Expand Down
15 changes: 11 additions & 4 deletions packages/database-typeorm/src/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ export class User {
@AfterLoad()
public async getServices() {
this.services = (this.allServices || []).reduce((acc, service) => {
set(acc, service.name, [
...[].concat(get(acc, service.name, [])),
{ ...(service.token ? { token: service.token } : {}), ...service.options },
]);
if (['password.reset', 'email.verificationTokens'].includes(service.name)) {
set(acc, service.name, [
...[].concat(get(acc, service.name, [])),
{ ...(service.token ? { token: service.token } : {}), ...service.options },
]);
} else {
set(acc, service.name, {
...(service.token ? { token: service.token } : {}),
...service.options,
});
}
return acc;
}, this.services);
}
Expand Down

0 comments on commit 0802624

Please sign in to comment.