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 { authentication } from 'wix-members-backend';23// Sample memberId value:4// 2f15ad3c-75e4-5df7-8ed4-13fee71433ca56export function myChangeLoginEmailFunction(memberId, newEmail) {7 return authentication.changeLoginEmail(memberId, newEmail)8 .then((updatedMember) => {9 const newLoginEmail = updatedMember.loginEmail;10 console.log('New login email is', newLoginEmail);1112 return updatedMember;13 })14 .catch((error) => {15 console.error(error);16 })17}
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.jsw *3 *****************************************/45import { authentication, currentMember } from 'wix-members-backend';67export async function myChangeLoginEmailFunction(newEmail) {89 // Get the currently logged-in member's ID10 const thisMember = await currentMember.getMember();11 const memberId = thisMember._id;1213 return await authentication.changeLoginEmail(memberId, newEmail);14}1516/*************17 * Page code *18 ************/1920import { changeCurrentMemberLogin } from 'backend/change-member-email';2122// ...2324$w('#changeEmail').onClick(async () => {2526 // If current member is a site contributor, they have the 'Admin' role.27 // Site contributors can change their login email through their Wix account28 // settings only.29 //30 // You can end the function if the member is also a site contributor.31 const currentMemberRoles = await currentMember.getRoles();32 const adminRole = currentMemberRoles.filter((role) => {33 return role.title === 'Admin';34 });35 if (adminRole.length > 0) {36 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.');37 return;38 }3940 // If #newEmail Text Input is set to type "Email",41 // you can end the function if the email isn't valid42 if (!$w('#newEmail').valid) {43 console.log('Invalid email');44 return;45 }4647 const newEmail = $w('#newEmail').value;4849 try {50 let updatedMember = await changeCurrentMemberLogin(newEmail);51 console.log('Email changed. Updated member:', updatedMember);52 } catch(error) {53 console.log('Email not changed');54 console.error(error);55 }56});
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.jsw *3 *****************************************/45import {authentication} from 'wix-members-backend';67export 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}161718/*************19 * Page code *20 ************/2122import { adminChangeMemberLogin } from 'backend/change-login-email';23import wixData from 'wix-data';2425$w.onReady(function () {26 // Only site contributors can load this data27 wixData.query('Members/PrivateMembersData').find()28 .then((results) => {2930 // Restructure the returned items array so it can be assigned31 // to the #memberList dropdown.32 const membersList = results.items.map((member) => {33 return {34 label: `${member.firstName} ${member.lastName} (${member.loginEmail})`,35 value: member._id36 }37 });3839 // Set the dropdown options40 $w('#memberList').options = membersList;41 });4243 $w('#changeLoginEmail').onClick(() => {44 const memberId = $w('#memberList').value;45 const newEmail = $w('#loginEmail').value;4647 adminChangeMemberLogin(memberId, newEmail);48 });4950});