Approve By Token Error Wix Users Backend

Hi All,

I am receiving the following exception when I attempt to approve a site member by token on the backend:

“server responded with - {“message”:“internal_error, details: {}”,“details”:{“error”:“internal_error”,“category”:“internal_error”}} (500)”

I have two functions on my backend that register users. One approves new members immediately and the other saves the new member’s approval token to a collection so that they can be approved later. This problem only occurs on the function that attempts to approve via the token stored in the database.

The function I am using to create the member and save their token:

export function createArtistMember(username, password, options) {
let userId;
let registering = wixUsersBackend.register(username, password, options). catch ((err) => {
throw error(“Wix Users Register Failed”, err);
});
let saveToken = registering.then((results) => {
let token = results.approvalToken;
userId = results.user.id;
let insert = {
“user”: userId,
“token”: results
}
return wixData.insert(“artistAuthorise”, insert, dataOptions);
})
. catch ((err) => {
throw error(“Artist Token Could Not Be Saved”, err)
});
let forReturn = saveToken.then(() => {
return userId;
})
return forReturn;
}

The function I am using to approve the member:

export function approveArtist(userId) {
let tokenRecord;
let query = wixData.query(“artistAuthorise”).eq(“user”, userId).find();

let authorising = query.then((results) => {
if (results.totalCount === 1) {
tokenRecord = results.items[0];
return wixUsersBackend.approveByToken(tokenRecord.token);
}
throw error(“Authorisation Token Could Not Be Found”, results)
}). catch ((err) => {
throw error(“Approval Failed”, err);
});

let cleaningUp = authorising.then((results) => {
let recordId = tokenRecord._id;
return wixData.remove(“artistAuthorise”, recordId);
}). catch ((err) => {
throw error(“Cleanup Failed”, err)
})

let forReturn = cleaningUp.then(() => {
let status = {
“User”: userId,
“Status”: “Approved”
}
return status;
});

return forReturn;
}

For the sake of testing, I have also attempted this by just copying and pasting a token into the wixUsersBackend.approveByToken() function directly from the collection. This results in same exception.

Hopefully I am making a mistake here because being unable to approve by tokens at a later time would be annoying. Anyone got any ideas? Happy to post more info if need be.

It’s been a while since this was posted by Camread, but for the sake of people who stumble on this in the future, 2 suggestions:

  1. Make sure to test this after publishing, not in preview mode
  2. Pre-existing users (meaning the emails) trying to register again will cause such an error I believe. Make sure to remove the users if you wish to test with the same email more than once.

IS there anyway to resend verification email to Pre-existing users (not been approved and been pending)

@barjatiyaabhishek
Please add a new forum post with a link to refer back to this post, rather than bumping an old thread from 2018.

It would also depend on how long the user has already had since the token was sent out to them. Wix only let them last for 30 hours, then you need to get them to do it all again.

https://www.wix.com/corvid/reference/wix-users-backend.html#approveByToken
The approveByToken() function returns a Promise that resolves to a session token when the specified user is approved. Tokens must be approved within 30 hours of token creation.

You might just find it easier for them to signup again and have another token email sent out so that they know that the token is still active.

If the verification email was not received by somebody, then you would really need to know why they had not got it first. Otherwise you could simply be sending out email after email and they not receive them etc.

Old post being closed.