Let members to delete their own accounts

Hi, I want members to give the option to delete their member accounts that they have created with my website, whenever they want.

I shall appreciate if you could kindly let me know whether this is possible, if yes, then how

2 Likes

Provide a “delete my account” button for logged in users, and then you can use the deleteMember() API function to delete a user when a logged in user clicks the button.

This is essential.

can you show us how?

Any idea on how to set up this function, as described by Yisrael?

What are you having trouble with? What do you have so far? What works? What doesn’t? Share your code here in a code block so you can get assistance.

@yisrael-wix Hi there. I have the same question. Here’s what I have so far:

import wixUsersBackend from 'wix-users-backend';

export function deleteUser() {
 let user = wixUsersBackend.currentUser;

  wixUsersBackend.deleteUser(user .id)
    .then( () => {
 // user has been deleted
    })
    .catch( (err) => {
 // there was an error deleting the user
    });
}

$w.onReady(function () {
 
});

export function deleteAccount_click(event) {
    deleteUser();
}

“deleteAccount” is the ID of my button.
Thank you so much for your help :slight_smile:

PS: Had to add a space between user & .id, else it wouldn’t let me post :astonished:

@harryhoe01 If the code is not working, please check the Property Panel of your #deleteAccount button has ‘connected’ with the code. Sometimes if you undo something, the function does not export but the code exists.

@certified-code Thank you for your reply!
When I use the button as a “logout” button it does log out. So it seems the button connected.
But the code is correct in your opinion?

@harryhoe01 Try filling in something under the “onReady” function.

Hi everybody,

I’m new on Velo and I’m trying to create a button where a member can delete its own account (really important for RGPD issues, I don’t know why this button didn’t exist natively).

My code works well with the getMember function, I recover all information about my member. But, deleteMember doesn’t work. The log message : :“[“message: ‘’\ndetails:\n applicationError:\n description: Forbidden\n code: FORBIDDEN\n data: {}”]”

Why it’s forbidden?

Thanks a lot for your help.

// front file code

const OPTIONS = {
fieldsets : [ ‘FULL’ ]
}

$w . onReady ( function () {
});

export function button1_click ( event ) {
deleteMyCurrentMember ( OPTIONS );
}

// backend code

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

export function deleteMyCurrentMember ( options ) {
return currentMember . getMember ( options )
. then (( member ) => {
console . log ( ‘Member recover’ , member );
return members . deleteMember ( member . _id )
. then (() => {
console . log ( ‘Member deleted’ , member . _id );
})
. catch (( error ) => {
console . error ( error );
});
})
. catch (( error ) => {
console . error ( error );
})
}

Would really love help with this too. Not really confident with code but this is a function I need on my site.

Where should I write codes in Wix and how can I connect them to a button? Thank you!