Hello everyone.
I have a Dynamic Page which I’m using that allows users to edit their own data (form) submissions but I have a problem where any user can view another user’s edit page.
To solve this, I thought I could implement a JavaScript “checker” that ensures only the owner can view the page. Here’s my code so far… but I’m missing some things.
$w.onReady(function () {
$w("#dataset4").onReady(async() => {
($w("#dataset4").getCurrentItem())
.................
if (wixUsers.currentUser.Owner) { // of the current item?
console.log("Loading edit page")
}
else {
wixLocation.to("www.google.com");
console.log("Error: You do not have permission to edit")
}
});
To clarify:
I want to check by using code if the currently logged in user is the owner of the record, and if not show redirect them somewhere. If it is the correct user, they will be able to see the page.
Any ideas on what I’m missing OR how I can achieve this some other way? Examples are appreciated.
1, what does the error say?
2, make sure the “owner” field in your collection contains the user id.
3, I have no idea why you put “async” in your onReady() function.
4, You’re missing }) in the end of your code.
5, I don’t know if you imported wixLocation (it’s not in the code you posted)