changeLoginEmail( )
Changes a member's login email address.
Description
The changeLoginEmail()
function returns a Promise
that resolves to an updated member object
when the specified member's login email address is changed.
After running this function, the specified member can log in with the new email address. If the member uses social login (for example, Google login) and the member tries to log in with the old email address, they will be re-registered with the old email address.
Site contributors can use changeLoginEmail()
to change another member's login email.
Members who are not site contributors can use changeLoginEmail()
to change their own login email only.
Note:
changeLoginEmail()
cannot be used for site contributors. Site contributors can change their login emails from their Wix account settings.
Syntax
function changeLoginEmail(memberId: string, newEmail: string): Promise<Member>
changeLoginEmail Parameters
NAME
TYPE
DESCRIPTION
Member ID.
New login email address.
Returns
Fulfilled - Member with the updated login email address. Rejected - Error message.
Return Type:
NAME
TYPE
DESCRIPTION
Member ID.
Email used by the member to log in to the site.
Member site access status.
One of:
"PENDING"
: Member created and is waiting for approval by site owner."APPROVED"
: Member can log in to the site."OFFLINE"
: Member is a guest author for the site blog and cannot log in to the site."BLOCKED"
: Member is blocked and cannot log in to the site."UNKNOWN"
: Insufficient permissions to get the status.
Contact ID.
Member privacy status.
One of:
"PUBLIC"
: Member is visible to everyone."PRIVATE"
: Member is hidden from site visitors and other site members. Member is returned only to site contributors and apps with the appropriate permissions."UNKNOWN"
: Insufficient permissions to get the status.
Member activity status.
One of:
"ACTIVE"
: Member can write forum posts and blog comments."MUTED"
: Member cannot write forum posts or blog comments."UNKNOWN"
: Insufficient permissions to get the status.
Date and time when the member was created.
Date and time when the member was updated.
Date and time when the member last logged in to the site.
Member's contact information. Contact information is stored in the Contact List.
Profile display info.
Was this helpful?
1import { Permissions, webMethod } from 'wix-web-module';2import { authentication } from 'wix-members-backend';34// Sample memberId value:5// 2f15ad3c-75e4-5df7-8ed4-13fee71433ca67// Sample newEmail value:8// janedoe@example.com910export const myChangeLoginEmailFunction = webMethod(Permissions.Anyone, async (memberId, newEmail) => {11 try {12 const updatedMember = await authentication.changeLoginEmail(memberId, newEmail);13 const newLoginEmail = updatedMember.loginEmail;14 console.log('New login email is', newLoginEmail);1516 return updatedMember;17 } catch (error) {18 console.error(error);19 }20});
The code in this example first checks that (1) the new login email is a valid email address, and (2) the member is not also a site contributor.
If both of these checks pass, the new login email provided by the currently logged-in member is passed to a backend function that automatically retrieves the member's ID and changes the login email.
1/******************************************2 * Backend code - change-member-email.web.js *3 *****************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { authentication, currentMember } from 'wix-members-backend';78export const myChangeLoginEmailFunction = webMethod(Permissions.Anyone, async (newEmail) => {910 // Get the currently logged-in member's ID11 const thisMember = await currentMember.getMember();12 const memberId = thisMember._id;1314 return await authentication.changeLoginEmail(memberId, newEmail);15});1617/*************18 * Page code *19 ************/2021import { myChangeLoginEmailFunction } from 'backend/change-member-email.web';2223// ...2425$w('#changeEmail').onClick(async () => {2627 // If current member is a site contributor, they have the 'Admin' role.28 // Site contributors can change their login email through their Wix account29 // settings only.30 //31 // You can end the function if the member is also a site contributor.32 const currentMemberRoles = await currentMember.getRoles();33 const adminRole = currentMemberRoles.filter((role) => {34 return role.title === 'Admin';35 });36 if (adminRole.length > 0) {37 console.log('Current member is a site contributor. Login email can\'t be changed with Velo. Member should change email through their Wix account settings.');38 return;39 }4041 // If #newEmail Text Input is set to type "Email",42 // you can end the function if the email isn't valid43 if (!$w('#newEmail').valid) {44 console.log('Invalid email');45 return;46 }4748 const newEmail = $w('#newEmail').value;4950 try {51 let updatedMember = await myChangeLoginEmailFunction(newEmail);52 console.log('Email changed. Updated member:', updatedMember);53 } catch(error) {54 console.log('Email not changed');55 console.error(error);56 }57});58
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()
.
1/******************************************2 * Backend code - change-member-email.web.js *3 *****************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { authentication } from 'wix-members-backend';78export const changeMemberLogin = webMethod(Permissions.Anyone, async (memberId, newEmail) => {9 try {10 const updatedMember = await authentication.changeLoginEmail(memberId, newEmail);11 console.log('Member email changed');12 return updatedMember;13 } catch (error) {14 console.error(error);15 }16});171819/*************20 * Page code *21 ************/2223import { changeMemberLogin } from 'backend/change-member-email.web';24import wixData from 'wix-data';2526$w.onReady(function () {27 // Only site contributors can load this data28 wixData.query('Members/PrivateMembersData')29 .find()30 .then((results) => {31 // Restructure the returned items array so it can be assigned32 // to the #memberList dropdown.33 const membersList = results.items.map((member) => {34 return {35 label: `${member.firstName} ${member.lastName} (${member.loginEmail})`,36 value: member._id,37 };38 });3940 // Set the dropdown options41 $w('#memberList').options = membersList;42 });4344 $w('#changeLoginEmail').onClick(() => {45 const memberId = $w('#memberList').value;46 const newEmail = $w('#loginEmail').value;4748 changeMemberLogin(memberId, newEmail);49 });50});51