Search.../

updateSlug( )

Changes the currently logged-in member's slug.

Description

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.

Syntax

function updateSlug(slug: string): Promise<Member>

updateSlug Parameters

NAME
TYPE
DESCRIPTION
slug
string

New slug.

Returns

Fulfilled - Updated member.

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?

Update the currently logged-in member's slug

Copy Code
1import { currentMember } from 'wix-members-backend';
2
3// Sample slug value:
4// 'claude-morales-new-slug'
5
6export const myUpdateSlugFunction = webMethod(Permissions.Anyone, (slug) => {
7 return currentMember.updateSlug(slug)
8 .then((updatedMember) => {
9 const updatedSlug = updatedMember.profile.slug;
10 const memberProfilePage = `https://yoursite.com/profile/${updatedSlug}/profile`;
11
12 return updatedMember;
13 })
14 .catch((error) => {
15 console.error(error);
16 });
17}
18
19/* Promise resolves to:
20 * {
21 * "_id": "f32cbc51-a331-442b-86c2-2c664613e8b9",
22 * "_createdDate": "2021-08-02T23:14:42.000Z",
23 * "_updatedDate": "2021-08-02T23:14:58.345Z",
24 * "loginEmail": "claude.morales@example.com",
25 * "status": "APPROVED",
26 * "contactId": "f32cbc51-a331-442b-86c2-2c664613e8b9",
27 * "privacyStatus": "PUBLIC",
28 * "activityStatus": "ACTIVE",
29 * "lastLoginDate": "2021-08-04T05:10:21.000Z",
30 * "contactDetails": {
31 * "firstName": "Claude",
32 * "lastName": "Morales",
33 * "phones": [
34 * "0747-769-460"
35 * ],
36 * "emails": [
37 * "claude.morales@example.com"
38 * ],
39 * "addresses": [
40 * {
41 * "_id": "f0f4d905-488d-44db-9080-fc29078cfad5",
42 * "addressLine": "9373 Park Avenue",
43 * "addressLine2": "Berkshire",
44 * "city": "Ely",
45 * "subdivision": "GB-ENG",
46 * "country": "GB",
47 * "postalCode": "PD50 8EU"
48 * },
49 * {
50 * "country": "IL"
51 * }
52 * ],
53 * "customFields": {}
54 * },
55 * "profile": {
56 * "nickname": "Claude Morales",
57 * "slug": "claude-morales-new-slug"
58 * }
59 * }
60 */
Allow a member to change their own slug

You can allow the currently logged-in member to change their slug by providing a text box (in this example, #newSlug) and passing the value to a backend function that calls updateSlug().

This example also includes backend validation, which enforces a limit on the characters the slug can include. This allows you to apply the same validation to any number of inputs across your site.

Copy Code
1/*************************************
2 * Backend code - change-slug.web.js *
3 ************************************/
4
5import { currentMember } from 'wix-members-backend';
6
7export async function changeMemberSlug(slug) {
8 // Validate the slug passed to this function.
9 // This rule enforces that the slug can contain only lowercase letters (a-z),
10 // numbers (0-9), hyphens (-), underscores (_), and pluses (+).
11 // If the test passes, isValid is set to true.
12 const comparison = /^[a-z0-9-_+]+$/m;
13 const isValid = comparison.test(slug);
14
15 if (isValid === true) {
16
17 const updatedMember = await currentMember.updateSlug(slug);
18 return {
19 result: 'updated',
20 member: updatedMember
21 };
22
23 } else {
24
25 return {
26 result: 'not_updated',
27 reason: 'Invalid slug. Slug can contain only a-z, 0-9, -, _, or +'
28 };
29
30 }
31}
32
33
34/*************
35 * Page code *
36 ************/
37
38import { changeMemberSlug } from 'backend/change-slug';
39
40// ...
41
42$w('#updateSlugButton').onClick(async () => {
43 console.log('Updating slug...');
44
45 const newSlug = $w('#newSlug').value;
46
47 // Pass the new slug to the backend changeMemberSlug()
48 const updateSlugResponse = await changeMemberSlug(newSlug);
49
50 if (updateSlugResponse.result === 'updated') {
51
52 const updatedSlug = updateSlugResponse.member.profile.slug;
53 const memberProfilePage = `https://yoursite.com/profile/${updatedSlug}/profile`;
54 console.log('Slug updated. New member profile page:', memberProfilePage);
55
56 } else {
57
58 console.log('Slug not updated. Response:', updateSlugResponse);
59 // Handle case where slug is not updated
60
61 }
62});