> 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`).
> - 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: updateSlug(slug: string)

# Method package: wixMembersBackend

# Method menu location: wixMembersBackend --> CurrentMember --> updateSlug

# Method Link: https://dev.wix.com/docs/velo/apis/wix-members-backend/current-member/update-slug.md

# Method Description:

Changes the currently logged-in member's slug.

The `updateSlug()` function returns a Promise that resolves to a member
after the member's slug is changed.
> **Note:**
> The APIs in `CurrentMember` are only partially functional when previewing your site. View a published version of your site to see their complete functionality.



# Method Code Examples:

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

## Update the currently logged-in member's slug

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

// Sample slug value:
// 'claude-morales-new-slug'

export const myUpdateSlugFunction = webMethod(Permissions.Anyone, (slug) => {
  return currentMember.updateSlug(slug)
    .then((updatedMember) => {
      const updatedSlug = updatedMember.profile.slug;
      const memberProfilePage = `https://yoursite.com/profile/${updatedSlug}/profile`;

      return updatedMember;
    })
    .catch((error) => {
      console.error(error);
    });
});

/* Promise resolves to:
 * {
 *     "_id": "f32cbc51-a331-442b-86c2-2c664613e8b9",
 *     "_createdDate": "2021-08-02T23:14:42.000Z",
 *     "_updatedDate": "2021-08-02T23:14:58.345Z",
 *     "loginEmail": "claude.morales@example.com",
 *     "status": "APPROVED",
 *     "contactId": "f32cbc51-a331-442b-86c2-2c664613e8b9",
 *     "privacyStatus": "PUBLIC",
 *     "activityStatus": "ACTIVE",
 *     "lastLoginDate": "2021-08-04T05:10:21.000Z",
 *     "contactDetails": {
 *         "firstName": "Claude",
 *         "lastName": "Morales",
 *         "phones": [
 *             "0747-769-460"
 *         ],
 *         "emails": [
 *             "claude.morales@example.com"
 *         ],
 *         "addresses": [
 *             {
 *                 "_id": "f0f4d905-488d-44db-9080-fc29078cfad5",
 *                 "addressLine": "9373 Park Avenue",
 *                 "addressLine2": "Berkshire",
 *                 "city": "Ely",
 *                 "subdivision": "GB-ENG",
 *                 "country": "GB",
 *                 "postalCode": "PD50 8EU"
 *             },
 *             {
 *                 "country": "IL"
 *             }
 *         ],
 *         "customFields": {}
 *     },
 *     "profile": {
 *         "nickname": "Claude Morales",
 *         "slug": "claude-morales-new-slug"
 *     }
 * }
 */
```

## Allow a member to change their own slug

```javascript
/*************************************
 * Backend code - change-slug.web.js *
 ************************************/

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

export const changeMemberSlug = webMethod(Permissions.Anyone, async (slug) => {
  // Validate the slug passed to this function.
  // This rule enforces that the slug can contain only lowercase letters (a-z),
  // numbers (0-9), hyphens (-), underscores (_), and pluses (+).
  // If the test passes, isValid is set to true.
  const comparison = /^[a-z0-9-_+]+$/m;
  const isValid = comparison.test(slug);

  if (isValid === true) {

    const updatedMember = await currentMember.updateSlug(slug);
    return {
      result: 'updated',
      member: updatedMember
    };

  } else {

    return {
      result: 'not_updated',
      reason: 'Invalid slug. Slug can contain only a-z, 0-9, -, _, or +'
    };

  }
});


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

import { changeMemberSlug } from 'backend/change-slug.web';

// ...

$w('#updateSlugButton').onClick(async () => {
  console.log('Updating slug...');

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

  // Pass the new slug to the backend changeMemberSlug()
  const updateSlugResponse = await changeMemberSlug(newSlug);

  if (updateSlugResponse.result === 'updated') {

    const updatedSlug = updateSlugResponse.member.profile.slug;
    const memberProfilePage = `https://yoursite.com/profile/${updatedSlug}/profile`;
    console.log('Slug updated. New member profile page:', memberProfilePage);

  } else {

    console.log('Slug not updated. Response:', updateSlugResponse);
    // Handle case where slug is not updated

  }
});

```

---