File tree Expand file tree Collapse file tree
packages/services/server/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,22 +103,22 @@ export async function registerSupertokensAtHome(
103103 parsedBody . data . formFields . find ( field => field . id === 'firstName' ) ?. value ?? null ;
104104 const lastName =
105105 parsedBody . data . formFields . find ( field => field . id === 'lastName' ) ?. value ?? null ;
106- const email = parsedBody . data . formFields . find ( field => field . id === 'email' ) ?. value ?? '' ;
106+ const rawEmail = parsedBody . data . formFields . find ( field => field . id === 'email' ) ?. value ?? '' ;
107107 const password =
108108 parsedBody . data . formFields . find ( field => field . id === 'password' ) ?. value ?? '' ;
109109
110- const emailRegex = / ^ ( (? ! \. ) [ \w - _ . ] * [ ^ . ] ) ( @ \w + ) ( \. \w + ( \. \w + ) ? [ ^ . \W ] ) $ / gim ;
110+ const emailResult = z . string ( ) . email ( ) . safeParse ( rawEmail ) ;
111111
112112 // Verify email
113- if ( ! emailRegex . test ( email ) ) {
113+ if ( ! emailResult . success ) {
114114 return rep . send ( {
115115 status : 'GENERAL_ERROR' ,
116116 message : 'Invalid email provided.' ,
117117 } ) ;
118118 }
119119
120120 // Lookup user
121- let user = await supertokensStore . lookupEmailUserByEmail ( email ) ;
121+ let user = await supertokensStore . lookupEmailUserByEmail ( rawEmail ) ;
122122
123123 if ( user ) {
124124 return rep . send ( {
@@ -151,13 +151,13 @@ export async function registerSupertokensAtHome(
151151
152152 // create user
153153 user = await supertokensStore . createEmailPasswordUser ( {
154- email,
154+ email : emailResult . data ,
155155 passwordHash,
156156 } ) ;
157157
158158 const ensureUserResult = await storage . ensureUserExists ( {
159159 superTokensUserId : user . userId ,
160- email,
160+ email : emailResult . data ,
161161 oidcIntegration : null ,
162162 firstName,
163163 lastName,
You can’t perform that action at this time.
0 commit comments