How to properly change username ?

  • Hello,

    I wrote a plugin to login my users from another app to my NodeBB forum.
    In my app, my users are allowed to change their usernames so I overwrite user's field by using this :

    User.setUserField(uid, 'username', username);
    User.setUserField(uid, 'userslug', utils.slugify(username));

    It's working, but when the user go to his profile, there is an error.
    The profile can be found by changing the username (userslug) in the URL by the old one.
    How could I make this work entirely ?

    Another question : where could I found the list of allowed characters in NodeBB's username ? It seems that "(" is not allowed for example.


  • NodeBB Admin

    You should use user.updateProfile try

    user.updateProfile(uidOfUserMakingCall, { uid: uidOfUserBeingEdited, username: 'newUsername' }, callback);

    For valid usernames you can check the function utils.isUsernameValid

  • Thanks, it's working, i have juste corrected user in User.

    Another question again : is it possible to force refresh of the page to make sure that the change of username is correct ?

  • NodeBB Admin

    calling ajaxify.refresh() should refresh the page.

Suggested Topics

| | | |