Change a member's login email from an admin page

The code in this example allows a site contributor with admin permissions to change any member’s login email.
It starts by populating the #memberList dropdown list with data from the Members/PrivateMemberData collection. The site contributor selects the member whose email they want to change, then specifies a new email in the #loginEmail text input. The member ID and new email are passed to a backend function that calls changeLoginEmail().
/******************************************
2 * Backend code - change-member-email.jsw *
3 ****************************/
4
5 import { authentication } from ‘wix-members-backend’;
6
7 export async function changeMemberLogin ( memberId , newEmail ) {
8 try {
9 const updatedMember = await authentication . changeLoginEmail ( memberId , newEmail );
10 console . log (‘Member email changed’);
11 return updatedMember ;
12 } catch ( error ) {
13 console . error ( error );
14 }
15 }
16
17
18 /

19 * Page code *
20 ************/
21
22 import { adminChangeMemberLogin } from ‘backend/change-login-email’;
23 import wixData from ‘wix-data’;
24
25$w . onReady ( function () {
26 // Only site contributors can load this data
27 wixData . query (‘Members/PrivateMembersData’). find ()
28 . then (( results ) => {
29
30 // Restructure the returned items array so it can be assigned
31 // to the #memberList dropdown.
32 const membersList = results . items . map (( member ) => {
33 return {
34 label : ${ member . firstName } ${ member . lastName } (${ member . loginEmail }),
35 value : member . _id
36 }
37 });
38
39 // Set the dropdown options
40 $w (‘#memberList’). options = membersList ;
41 });
42
43 $w (‘#changeLoginEmail’). onClick (() => {
44 const memberId = $w (‘#memberList’). value ;
45 const newEmail = $w (‘#loginEmail’). value ;
46
47 adminChangeMemberLogin ( memberId , newEmail );
48 });
49
50 });

I think this code is not right. Please check and confirm.

HI @yisrael-wix … I would like to invite you to check this code.

I want to create an admin page where I will be able to update the login email of the users manually. And once the email updated they will receive an email in the new email address confirming that the email changed.