@@ -99,13 +99,16 @@ export async function createAuth0User(
9999 const accessToken = await getAuth0ManagementToken ( ) ;
100100
101101 // Build create user request - Auth0 will auto-generate user_id
102+ // We set email_verified: true because admins control user creation
103+ // We set verify_email: false to prevent Auth0 sending verification email
104+ // Instead, we send a password change email so users can set their password
102105 const createUserRequest : CreateAuth0UserRequest = {
103106 connection : connection ,
104107 email : email ,
105108 name : email , // Use email as name
106109 password : generateTempPassword ( ) ,
107- email_verified : false ,
108- verify_email : true ,
110+ email_verified : true ,
111+ verify_email : false ,
109112 app_metadata : {
110113 authorization : {
111114 roles : authClaims ,
@@ -133,6 +136,38 @@ export async function createAuth0User(
133136 return createdUser ;
134137}
135138
139+ /**
140+ * Send password change email to user via Auth0 Authentication API
141+ * This allows new users to set their password after account creation
142+ * @param email - User email address
143+ */
144+ export async function sendPasswordChangeEmail ( email : string ) : Promise < void > {
145+ const domain = auth0Config . domain as string ;
146+ const clientId = auth0Config . clientId as string ;
147+ const connection = ( auth0Config . userDbConnection as string ) || 'Username-Password-Authentication' ;
148+
149+ if ( ! domain || ! clientId ) {
150+ throw new Error ( 'AUTH0_DOMAIN or AUTH0_CLIENT_ID is not configured' ) ;
151+ }
152+
153+ const response = await fetch ( `https://${ domain } /dbconnections/change_password` , {
154+ method : HTTP_METHODS . POST ,
155+ headers : {
156+ 'Content-Type' : 'application/json' ,
157+ } ,
158+ body : JSON . stringify ( {
159+ client_id : clientId ,
160+ email : email ,
161+ connection : connection ,
162+ } ) ,
163+ } ) ;
164+
165+ if ( ! response . ok ) {
166+ const error = await response . text ( ) ;
167+ throw new Error ( `Failed to send password change email: ${ error } ` ) ;
168+ }
169+ }
170+
136171/**
137172 * Delete a user from Auth0
138173 * @param auth0UserId - Auth0 user ID (e.g., "auth0|123456")
0 commit comments