I have a router which contains the following function. My goal is to check first whether the user is logged in and, if so, check they have the appropriate role to access the page.
export function marketplacelogin_Router(request) {
let user = wixUsersBackend.currentUser;
if (user.loggedIn) {
user.getRoles()
.then((roles) => {
if (roles.some(role => role.name === "Administrator")) {
return redirect("/marketplace")
}
})
}
}
When I redirect to the page, I get a time-out. I assume it is related to the getRoles(). I have tried adding a delay but it doesn’t work. How can I query the role of the logged in user in the backend?