1
- import { CreateUserServicePassword , ctxAsyncLocalStorage } from '@accounts/types' ;
1
+ import { CreateUserServicePassword } from '@accounts/types' ;
2
2
import {
3
3
AccountsPassword ,
4
4
CreateUserErrors ,
@@ -18,10 +18,8 @@ export const Mutation: MutationResolvers = {
18
18
19
19
const userId = user . id ;
20
20
21
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
22
- await injector . get ( AccountsPassword ) . addEmail ( userId , newEmail ) ;
23
- return null ;
24
- } ) ;
21
+ await injector . get ( AccountsPassword ) . addEmail ( userId , newEmail ) ;
22
+ return null ;
25
23
} ,
26
24
changePassword : async ( _ , { oldPassword, newPassword } , ctx ) => {
27
25
const { user, injector } = ctx ;
@@ -32,10 +30,8 @@ export const Mutation: MutationResolvers = {
32
30
33
31
const userId = user . id ;
34
32
35
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
36
- await injector . get ( AccountsPassword ) . changePassword ( userId , oldPassword , newPassword ) ;
37
- return null ;
38
- } ) ;
33
+ await injector . get ( AccountsPassword ) . changePassword ( userId , oldPassword , newPassword ) ;
34
+ return null ;
39
35
} ,
40
36
createUser : async ( _ , { user } , ctx ) => {
41
37
const { injector, infos } = ctx ;
@@ -44,43 +40,41 @@ export const Mutation: MutationResolvers = {
44
40
45
41
let userId : string ;
46
42
47
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
48
- try {
49
- userId = await accountsPassword . createUser ( user as CreateUserServicePassword ) ;
50
- } catch ( error ) {
51
- // If ambiguousErrorMessages is true we obfuscate the email or username already exist error
52
- // to prevent user enumeration during user creation
53
- if (
54
- accountsServer . options . ambiguousErrorMessages &&
55
- error instanceof AccountsJsError &&
56
- ( error . code === CreateUserErrors . EmailAlreadyExists ||
57
- error . code === CreateUserErrors . UsernameAlreadyExists )
58
- ) {
59
- return { } ;
60
- }
61
- throw error ;
43
+ try {
44
+ userId = await accountsPassword . createUser ( user as CreateUserServicePassword ) ;
45
+ } catch ( error ) {
46
+ // If ambiguousErrorMessages is true we obfuscate the email or username already exist error
47
+ // to prevent user enumeration during user creation
48
+ if (
49
+ accountsServer . options . ambiguousErrorMessages &&
50
+ error instanceof AccountsJsError &&
51
+ ( error . code === CreateUserErrors . EmailAlreadyExists ||
52
+ error . code === CreateUserErrors . UsernameAlreadyExists )
53
+ ) {
54
+ return { } ;
62
55
}
56
+ throw error ;
57
+ }
63
58
64
- if ( ! accountsServer . options . enableAutologin ) {
65
- return {
66
- userId : accountsServer . options . ambiguousErrorMessages ? null : userId ,
67
- } ;
68
- }
59
+ if ( ! accountsServer . options . enableAutologin ) {
60
+ return {
61
+ userId : accountsServer . options . ambiguousErrorMessages ? null : userId ,
62
+ } ;
63
+ }
69
64
70
- // When initializing AccountsServer we check that enableAutologin and ambiguousErrorMessages options
71
- // are not enabled at the same time
65
+ // When initializing AccountsServer we check that enableAutologin and ambiguousErrorMessages options
66
+ // are not enabled at the same time
72
67
73
- const createdUser = await accountsServer . findUserById ( userId ) ;
68
+ const createdUser = await accountsServer . findUserById ( userId ) ;
74
69
75
- // If we are here - user must be created successfully
76
- // Explicitly saying this to Typescript compiler
77
- const loginResult = await accountsServer . loginWithUser ( createdUser ! , infos ) ;
70
+ // If we are here - user must be created successfully
71
+ // Explicitly saying this to Typescript compiler
72
+ const loginResult = await accountsServer . loginWithUser ( createdUser ! , infos ) ;
78
73
79
- return {
80
- userId,
81
- loginResult,
82
- } ;
83
- } ) ;
74
+ return {
75
+ userId,
76
+ loginResult,
77
+ } ;
84
78
} ,
85
79
twoFactorSet : async ( _ , { code, secret } , ctx ) => {
86
80
const { user, injector } = ctx ;
@@ -92,10 +86,8 @@ export const Mutation: MutationResolvers = {
92
86
93
87
const userId = user . id ;
94
88
95
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
96
- await injector . get ( AccountsPassword ) . twoFactor . set ( userId , secret as any , code ) ;
97
- return null ;
98
- } ) ;
89
+ await injector . get ( AccountsPassword ) . twoFactor . set ( userId , secret as any , code ) ;
90
+ return null ;
99
91
} ,
100
92
twoFactorUnset : async ( _ , { code } , ctx ) => {
101
93
const { user, injector } = ctx ;
@@ -107,71 +99,61 @@ export const Mutation: MutationResolvers = {
107
99
108
100
const userId = user . id ;
109
101
110
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
111
- await injector . get ( AccountsPassword ) . twoFactor . unset ( userId , code ) ;
112
- return null ;
113
- } ) ;
102
+ await injector . get ( AccountsPassword ) . twoFactor . unset ( userId , code ) ;
103
+ return null ;
114
104
} ,
115
105
resetPassword : async ( _ , { token, newPassword } , ctx ) => {
116
106
const { injector, infos } = ctx ;
117
107
118
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
119
- return injector . get ( AccountsPassword ) . resetPassword ( token , newPassword , infos ) ;
120
- } ) ;
108
+ return injector . get ( AccountsPassword ) . resetPassword ( token , newPassword , infos ) ;
121
109
} ,
122
110
sendResetPasswordEmail : async ( _ , { email } , ctx ) => {
123
111
const { injector } = ctx ;
124
112
const accountsServer = injector . get ( AccountsServer ) ;
125
113
const accountsPassword = injector . get ( AccountsPassword ) ;
126
114
127
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
128
- try {
129
- await accountsPassword . sendResetPasswordEmail ( email ) ;
130
- } catch ( error ) {
131
- // If ambiguousErrorMessages is true,
132
- // to prevent user enumeration we fail silently in case there is no user attached to this email
133
- if (
134
- accountsServer . options . ambiguousErrorMessages &&
135
- error instanceof AccountsJsError &&
136
- error . code === SendResetPasswordEmailErrors . UserNotFound
137
- ) {
138
- return null ;
139
- }
140
- throw error ;
115
+ try {
116
+ await accountsPassword . sendResetPasswordEmail ( email ) ;
117
+ } catch ( error ) {
118
+ // If ambiguousErrorMessages is true,
119
+ // to prevent user enumeration we fail silently in case there is no user attached to this email
120
+ if (
121
+ accountsServer . options . ambiguousErrorMessages &&
122
+ error instanceof AccountsJsError &&
123
+ error . code === SendResetPasswordEmailErrors . UserNotFound
124
+ ) {
125
+ return null ;
141
126
}
127
+ throw error ;
128
+ }
142
129
143
- return null ;
144
- } ) ;
130
+ return null ;
145
131
} ,
146
132
verifyEmail : async ( _ , { token } , ctx ) => {
147
133
const { injector } = ctx ;
148
134
149
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
150
- await injector . get ( AccountsPassword ) . verifyEmail ( token ) ;
151
- return null ;
152
- } ) ;
135
+ await injector . get ( AccountsPassword ) . verifyEmail ( token ) ;
136
+ return null ;
153
137
} ,
154
138
sendVerificationEmail : async ( _ , { email } , ctx ) => {
155
139
const { injector } = ctx ;
156
140
const accountsServer = injector . get ( AccountsServer ) ;
157
141
const accountsPassword = injector . get ( AccountsPassword ) ;
158
142
159
- return ctxAsyncLocalStorage . run ( ctx , async ( ) => {
160
- try {
161
- await accountsPassword . sendVerificationEmail ( email ) ;
162
- } catch ( error ) {
163
- // If ambiguousErrorMessages is true,
164
- // to prevent user enumeration we fail silently in case there is no user attached to this email
165
- if (
166
- accountsServer . options . ambiguousErrorMessages &&
167
- error instanceof AccountsJsError &&
168
- error . code === SendVerificationEmailErrors . UserNotFound
169
- ) {
170
- return null ;
171
- }
172
- throw error ;
143
+ try {
144
+ await accountsPassword . sendVerificationEmail ( email ) ;
145
+ } catch ( error ) {
146
+ // If ambiguousErrorMessages is true,
147
+ // to prevent user enumeration we fail silently in case there is no user attached to this email
148
+ if (
149
+ accountsServer . options . ambiguousErrorMessages &&
150
+ error instanceof AccountsJsError &&
151
+ error . code === SendVerificationEmailErrors . UserNotFound
152
+ ) {
153
+ return null ;
173
154
}
174
- return null ;
175
- } ) ;
155
+ throw error ;
156
+ }
157
+ return null ;
176
158
} ,
177
159
} ;
0 commit comments