Change Member Login Email

I am trying to implement this code using the “change email from an admin page” example. I’ve set up both the backend code and page code, and built the admin page, but am having two issues:

  1. The login email is not updating on submission.
  2. The dropdown of member data only returns 50 members - our site has several hundred. I need to be able to access all. Here’s the code I’m using:

BACKEND

import {authentication} from ‘wix-members-backend’;

export async function changeMemberLogin(memberId, newEmail) {
try {
const updatedMember = await authentication.changeLoginEmail(memberId, newEmail);
console.log(‘Member email changed’);
return updatedMember;
} catch(error) {
console.error(error);
}
}

PAGE

import { adminChangeMemberLogin } from ‘backend/change-member-email’;
import wixData from ‘wix-data’;

$w.onReady(function () {
// Only site contributors can load this data
wixData.query(‘Members/PrivateMembersData’).find()
.then((results) => {

  // Restructure the returned items array so it can be assigned
  // to the #memberList dropdown.
  const membersList = results.items.map((member) => {
    return {
      label: `${member.firstName} ${member.lastName} (${member.loginEmail})`,
      value: member._id
    }
  });

  // Set the dropdown options
  $w('#dropdown1').options = membersList;
});

$w('#button71').onClick(() => {
  const memberId = $w('#dropdown1').value;
  const newEmail = $w('#input1').value;

  adminChangeMemberLogin(memberId, newEmail);
});

});

Does your console log give any clues? Some possibilities:

  1. Roles - our member coordinator has Back Office Manager role.
  2. Member dropdown - can’t remember if I ran into the 50-member limitation to select from all members. I added an input field to filter on last name, then that particular member appears in the dropdown.

export function button12_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit Working with the Properties & Events Panel
// Add your code for this event here:
const lName = $w(‘#input2’).value;

$w.onReady(function () {
// Only site contributors can load this data
wixData.query(‘Members/PrivateMembersData’)
.eq(“lastName”, lName)
.find()
.then((results) => {
console.log(results);
// Restructure the returned items array so it can be assigned
// to the #memberList dropdown.
const membersList = results.items.map((member) => {
return {
label: ${member.firstName} ${member.lastName} (${member.loginEmail}),
value: member._id
}
});

  // Set the dropdown options
  $w('#dropdown1').options = membersList;
});

Hey - thanks. I appreciate the additional code. I still can’t get this to work though. I am not a developer - totally self-taught - so definitely missing something. Unfortunately, nothing is appearing in the console logs. Here’s the updated full code. The last character is showing as an error at the very end - it does this no matter what the character is (blank space, semi colon, etc).

import { adminChangeMemberLogin } from ‘backend/change-member-email’;

import wixData from ‘wix-data’;

export function button72_click(event) {

// This function was added from the Properties & Events panel. To learn more, visit Working with the Properties & Events Panel

// Add your code for this event here:

const lName = $w(“#input2”).value;

$w.onReady(function () {

// Only site contributors can load this data

wixData.query(‘Members/PrivateMembersData’)

.eq(“lastName”, lName)

.find()

.then((results) => {

console.log(results);

// Restructure the returned items array so it can be assigned

// to the #memberList dropdown.

const membersList = results.items.map((member) => {

return {

label: ${member.firstName} ${member.lastName} (${member.loginEmail}),

value: member._id

}

});

// Set the dropdown options

$w(‘#dropdown1’).options = membersList;

});

$w(‘#button71’).onClick(() => {

const memberId = $w(‘#dropdown1’).value;

const newEmail = $w(‘#input1’).value;

adminChangeMemberLogin(memberId, newEmail);

});

Hey @custommembersite!

I’ve moved this over to its own topic.

It’s worth noting that you no longer need code to achieve this :wink: - Changing Your Member's Login Email | Help Center | Wix.com

This is amazing. Did it just come out today? I’ve been looking for this for over a year!

Hooray! Thanks Noah!

Just a quick update on the new Change Login Email function in Site Members: on selecting it the site contributor receives the following notice:

  • Make sure you verify this member before you change their email.*
  • This member won’t be able to log in to their account with any other methods they may have enabled, like social or SSO.*
  • This will also change the primary email in this member’s contact info.*

but on testing it, when changing from one GMail address to another I WAS able to sign in using the 2nd Gmail address’s credentials, and I found the primary email address in the member’s Contact info was not changed (I needed to manually update it).

So the new function in Site Member seems to work exactly like the backend code used to. But it certainly does the job, and my Membership person will not have to look at my ugly Change Login page any more!

It did come out super recently, so your hard work over the last year hasn’t been completely lost :muscle:

Glad to hear it’s what you’ve been needing :slight_smile: