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.