> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: changeLoginEmail(memberId: string, newEmail: string)

# Method package: wixMembersBackend

# Method menu location: wixMembersBackend --> Authentication --> changeLoginEmail

# Method Link: https://dev.wix.com/docs/velo/apis/wix-members-backend/authentication/change-login-email.md

# Method Description:

Changes a member's login email address.

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](https://manage.wix.com/account/account-settings).



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Change a member's login email

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { authentication } from 'wix-members-backend';

// Sample memberId value:
// 2f15ad3c-75e4-5df7-8ed4-13fee71433ca

// Sample newEmail value:
// janedoe@example.com

export const myChangeLoginEmailFunction = webMethod(Permissions.Anyone, async (memberId, newEmail) => {
  try {
    const updatedMember = await authentication.changeLoginEmail(memberId, newEmail);
    const newLoginEmail = updatedMember.loginEmail;
    console.log('New login email is', newLoginEmail);

    return updatedMember;
  } catch (error) {
    console.error(error);
  }
});
```

## Change the current member's login email

```javascript
/******************************************
 * Backend code - change-member-email.web.js *
 *****************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { authentication, currentMember } from 'wix-members-backend';

export const myChangeLoginEmailFunction = webMethod(Permissions.Anyone, async (newEmail) => {

  // Get the currently logged-in member's ID
  const thisMember = await currentMember.getMember();
  const memberId = thisMember._id;

  return await authentication.changeLoginEmail(memberId, newEmail);
});

/*************
 * Page code *
 ************/

import { myChangeLoginEmailFunction } from 'backend/change-member-email.web';

// ...

$w('#changeEmail').onClick(async () => {

  // If current member is a site contributor, they have the 'Admin' role.
  // Site contributors can change their login email through their Wix account
  // settings only.
  //
  // You can end the function if the member is also a site contributor.
  const currentMemberRoles = await currentMember.getRoles();
  const adminRole = currentMemberRoles.filter((role) => {
    return role.title === 'Admin';
  });
  if (adminRole.length > 0) {
    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.');
    return;
  }

  // If #newEmail Text Input is set to type "Email",
  // you can end the function if the email isn't valid
  if (!$w('#newEmail').valid) {
    console.log('Invalid email');
    return;
  }

  const newEmail = $w('#newEmail').value;

  try {
    let updatedMember = await myChangeLoginEmailFunction(newEmail);
    console.log('Email changed. Updated member:', updatedMember);
  } catch(error) {
    console.log('Email not changed');
    console.error(error);
  }
});

```

## Change a member's login email from an admin page

```javascript
/******************************************
 * Backend code - change-member-email.web.js *
 *****************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { authentication } from 'wix-members-backend';

export const changeMemberLogin = webMethod(Permissions.Anyone, async (memberId, newEmail) => {
  try {
    const updatedMember = await authentication.changeLoginEmail(memberId, newEmail);
    console.log('Member email changed');
    return updatedMember;
  } catch (error) {
    console.error(error);
  }
});


/*************
 * Page code *
 ************/

import { changeMemberLogin } from 'backend/change-member-email.web';
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('#memberList').options = membersList;
    });

  $w('#changeLoginEmail').onClick(() => {
    const memberId = $w('#memberList').value;
    const newEmail = $w('#loginEmail').value;

    changeMemberLogin(memberId, newEmail);
  });
});

```

---