@@ -5,6 +5,7 @@ import JWT from 'jsonwebtoken';
5
5
import { DateTime } from 'luxon' ;
6
6
import { Writable } from 'ts-essentials' ;
7
7
import { sessionFromContext } from '~/common/session' ;
8
+ import { disableAccessPolicies , EdgeDB } from '~/core/edgedb' ;
8
9
import {
9
10
DuplicateException ,
10
11
GqlContextType ,
@@ -38,6 +39,7 @@ export class AuthenticationService {
38
39
private readonly privileges : Privileges ,
39
40
@Logger ( 'authentication:service' ) private readonly logger : ILogger ,
40
41
private readonly repo : AuthenticationRepository ,
42
+ private readonly edgedb : EdgeDB ,
41
43
private readonly moduleRef : ModuleRef ,
42
44
) { }
43
45
@@ -48,7 +50,10 @@ export class AuthenticationService {
48
50
return token ;
49
51
}
50
52
51
- async register ( input : RegisterInput , session ?: Session ) : Promise < ID > {
53
+ async register (
54
+ { password, ...input } : RegisterInput ,
55
+ session ?: Session ,
56
+ ) : Promise < ID > {
52
57
// ensure no other tokens are associated with this user
53
58
if ( session ) {
54
59
await this . logout ( session . token ) ;
@@ -58,7 +63,10 @@ export class AuthenticationService {
58
63
try {
59
64
const userMod = await import ( '../user' ) ;
60
65
const users = this . moduleRef . get ( userMod . UserService , { strict : false } ) ;
61
- userId = await users . create ( input , session ) ;
66
+ userId = await this . edgedb . usingOptions (
67
+ disableAccessPolicies ,
68
+ async ( ) => await users . create ( input , session ) ,
69
+ ) ;
62
70
} catch ( e ) {
63
71
// remap field prop as `email` field is at a different location in register() than createPerson()
64
72
if ( e instanceof DuplicateException && e . field === 'person.email' ) {
@@ -67,7 +75,7 @@ export class AuthenticationService {
67
75
throw e ;
68
76
}
69
77
70
- const passwordHash = await this . crypto . hash ( input . password ) ;
78
+ const passwordHash = await this . crypto . hash ( password ) ;
71
79
await this . repo . savePasswordHashOnUser ( userId , passwordHash ) ;
72
80
73
81
return userId ;
0 commit comments