Dynamic Pages - Owner View Restrictions

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.

I’m not sure what exactly you’re trying to do, but you probably need to rephrase the ‘if’ condition.
Something like:

if(wixUsers.currentUser.id === $w("#dataset4").getCurrentItem().owner)

That looks exactly like what I’m trying to achieve, but I can’t seem to get it to work. I just get errors in the console.

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)

I’ve checked my collection and the user ID is in the owner field. I didn’t include all my code before, but I imported everything.

This code doesn’t make any errors occur, but doesn’t seem to change anything even if another user is logged in who is not the owner :

$w.onReady(function () {
if(wixUsers.currentUser.id === $w("#dynamicDataset").getCurrentItem().owner) {
    console.log("Yo have permission to edit")
  } else {
    wixLocation.to("https://www.google.com");
  }
});