Search.../

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
memberId
string

Member ID.

newEmail
string

New login email address.

Returns

Fulfilled - Member with the updated login email address. Rejected - Error message.

Return Type:

Promise<Member>
NAME
TYPE
DESCRIPTION
_id
string

Member ID.

loginEmail
string

Email used by the member to log in to the site.

status
string

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.
contactId
string

Contact ID.

privacyStatus
string

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.
activityStatus
string

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.
_createdDate
Date

Date and time when the member was created.

_updatedDate
Date

Date and time when the member was updated.

lastLoginDate
Date

Date and time when the member last logged in to the site.

contactDetails
ContactDetails

Member's contact information. Contact information is stored in the Contact List.

profile
Profile

Profile display info.

Was this helpful?

Change a member's login email

Copy Code
1import { authentication } from 'wix-members-backend';
2
3// Sample memberId value:
4// 2f15ad3c-75e4-5df7-8ed4-13fee71433ca
5
6export 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);
11
12 return updatedMember;
13 })
14 .catch((error) => {
15 console.error(error);
16 })
17}
Change the current member's login email

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.

Copy Code
1/******************************************
2 * Backend code - change-member-email.jsw *
3 *****************************************/
4
5import { authentication, currentMember } from 'wix-members-backend';
6
7export async function myChangeLoginEmailFunction(newEmail) {
8
9 // Get the currently logged-in member's ID
10 const thisMember = await currentMember.getMember();
11 const memberId = thisMember._id;
12
13 return await authentication.changeLoginEmail(memberId, newEmail);
14}
15
16/*************
17 * Page code *
18 ************/
19
20import { changeCurrentMemberLogin } from 'backend/change-member-email';
21
22// ...
23
24$w('#changeEmail').onClick(async () => {
25
26 // If current member is a site contributor, they have the 'Admin' role.
27 // Site contributors can change their login email through their Wix account
28 // 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 }
39
40 // If #newEmail Text Input is set to type "Email",
41 // you can end the function if the email isn't valid
42 if (!$w('#newEmail').valid) {
43 console.log('Invalid email');
44 return;
45 }
46
47 const newEmail = $w('#newEmail').value;
48
49 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});
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().

Copy Code
1/******************************************
2 * Backend code - change-member-email.jsw *
3 *****************************************/
4
5import {authentication} from 'wix-members-backend';
6
7export 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
22import { adminChangeMemberLogin } from 'backend/change-login-email';
23import 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});