How to resolve this dynamic page logout issue.
That is because whilst the user is logged in they have the permissions to view the dynamic page.
Once the user logs themselves out, then they do not have the permission to view that dynamic page and hence why you get the 403 Forbidden Error.
You simply need to move the user to another page after they logout to get around this.
https://www.wix.com/corvid/reference/wix-users.html#logout
https://www.wix.com/corvid/reference/wix-location.html#to
https://www.wix.com/corvid/reference/wix-window.lightbox.html#close
Read this old post for more info.
https://www.wix.com/corvid/forum/community-discussion/this-is-how-to-logout-and-go-to-the-page-of-your-choice
Here my Click Button Code: I set promise.all but its not working. Actually single button use for both login and logout.
export function loginbtn_click(event) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w( “#loginbtn” ).label = “Candidate Login” ;
Promise.all( [ wixLocation.to( ‘/’ ), wixUsers.logout() ] );
} )
}
// user is logged out
else {
let userId;
let userEmail;
// prompt the user to log in
wixUsers.promptLogin( { “mode” : “login” } )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query( “collectionname” )
.eq( “_id” , userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0 ) {
// create an item
const toInsert = {
“_id” : userId,
“email” : userEmail
};
// add the item to the collection
wixData.insert( " collectionname " , toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w( “#loginbtn” ).label = “Logout” ;
wixLocation.to( ‘/dashboard’ );
} )
. catch ( (err) => {
console.log(err);
} );
}
}
I created member only page.
https://restartrecruit.wixsite.com/dev1/candidateupdate/57edde7c-960f-494f-88da-4bde5df33e30
I redirect user from dashboard page to above dynamic page.
export function profilebtn_click(event) {
//Add your code for this event here:
wixLocation.to(/candidateupdate/${wixUsers.currentUser.id}
)
}
When a user clicks on button redirection works fine. But the issue is that when the user refreshes dynamic page 2nd or 3rd time it’s showing the following error. please see the screenshot. its permission error.
Can you please guide me on how to fix this issue?
Waiting for your reply.