dynamic page navigation error

I created a membership for my site that links to a dynamic page where you need to enter profile information.
My problem is that you can not get to the dynamic page and you get a 404 error page.
I’ve also seen a number of websites that you can register with Facebook or with a Google Account. I would like to add this to my site on this occasion.

Hi,
My guess is you have permission issues.
This article will be useful for you.
Feel free to paste your code here if you have more issues.
Roi

I checked and there is no premission issue.
this is mt code:

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#loginButton”).label = “Logout”;
$w(“#warrantyButton”).show();
}
else {
$w(“#loginButton”).label = “Login”;
$w(“#warrantyButton”).hide();
}
} );

export function loginButton_onClick(event) {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginButton”).label = “Login”;
$w(“#warrantyButton”).hide();
} );
}
// 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("warrantycard") 
      .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("warrantycard", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 
    } 
    // update buttons accordingly 
    $w("#loginButton").label = "Logout"; 
    $w("#warrantyButton").show(); 
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}
}
export function warrantyButton_onClick(event) {
wixLocation.to(/warrantycard/Registration${wixUsers.currentUser.id});
}

Hi,
Can you please share a link to your URL ?
Roi

let me know when i can delete it

Hi,
I found some errors.
The first one is in the Data Hook.
getFullYear() method gets an error. Probably because that variable’s field doesn’t fit the requirements of Date object.
It breaks the function and doesn’t returns the item.
The second one is the warrantyButton_onClick function,
You forgot “/” before the $ sign.

wixLocation.to(`/warrantycard/Registration${wixUsers.currentUser.id}`);  // need to add "/" before the $ sign
wixLocation.to(`/warrantycard/Registration/${wixUsers.currentUser.id}`); // like this

Good luck!
Roi

thank you its worked when I deleted my hook but the problem is that this hook is necessary and the wix expert helped me with this code.

Hi,
Don’t delete your hook.
I suggest to use console.log for every variable you create.
Roi

export function warrantycard_beforeInsert(item , context)
{
let date = item.dateOfPurchase;
let day = date.getDate();
let month = date.getMonth()+1;
let year = date.getFullYear();
let dateStr = year + “/” + month + “/” + day();
item.dateOfPurchase = dateStr();
let twoYearsFromNow = new Date(year + 2, month, day);
item.invalidDate = twoYearsFromNow;
console.log(item.dateOfPurchase , item.invalidDate);

}

is the code I wrote is what you ment?

Yes,
Add console.log after every variable you create and check if you get the expected result.
If you can, paste here a screenshot of it.
Roi

Sorry I really didnt understand you

What actions should I do to help me locate and correct the problem?

  • I clicked preview and could not figure out if what I did was right …
export function warrantycard_beforeInsert(item , context) {
console.log(item);
let date = item.dateOfPurchase;
console.log(date);
let day = date.getDate();
console.log(day); 
let month = date.getMonth()+1;
console.log(month); 
let year = date.getFullYear();
console.log(year); 
let dateStr = year + "/" + month + "/" + day();
console.log(dateStr);
item.dateOfPurchase = dateStr();
console.log(item.dateOfPurchase);
let twoYearsFromNow = new Date(year + 2, month, day);
console.log(twoYearsFromNow);
	item.invalidDate = twoYearsFromNow;
console.log(item.invalidDate);
return item;
}

Roi

Hi,
Can you please share a link to your site ?
Roi

Hi, I found some problems.
This is the object you try to add as an item to the collection.

  const toInsert = {
            "_id": userId,
            "email": userEmail
          };

In the before insert hook you can’t manipulate with date methods because is has only these keys: _id, email and _owner. you don’t have dateOfPurchase. that is why the hooks breaks and the new item is not inserted.
Handle the “toInsert” object before the hood (add the dateOfPurchase).
Good luck!
Roi

is it supposed to look like this?

const toInsert = {
“_id”: userId,
“email”: userEmail ,
“dateOfPurchase”: userDate };

or like this?

function insert(collectionName: warrantycard, item: dateOfPurchase,
[options:WixDataOptions]): Promise
}
export function warrantycard_beforeInsert(item , context)
{ console.log(item); let date = item.dateOfPurchase;
console.log(date); let day = date.getDate();
console.log(day); let month = date.getMonth()+1;
console.log(month); let year = date.getFullYear();
console.log(year); let dateStr = year + “/” + month + “/” + day();
console.log(dateStr); item.dateOfPurchase = dateStr();
console.log(item.dateOfPurchase);
let twoYearsFromNow = new Date(year + 2, month, day);
console.log(twoYearsFromNow);
item.invalidDate = twoYearsFromNow;
console.log(item.invalidDate); return item; }

Mr. Bendet,

You seem to be the “go to” person on this subject and I have reviewed all of your posts on the matter but I am still stuck. I have spent more than 20 hours on this glitch and keep sliding down my chair each passing hour. Can you please offer some advice as I am running out of chair?

I have checked permissions, connections, links and my code and I still cannot seem to find why when I click on my “profile” button I get an error 404. I have even changed permissions to “everyone” but it still does the same thing.

My login page is pretty much a copy of the code I found through the Wix Editor Help when I entered “Member Profile Page” and is pasted below.

I will even forward “cookies of your choice” if you can help.

Michael

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#loginButton”).label = “Logout”;
$w(“#profileButton”).show();
}
else {
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).hide();
}
} )

;
export function loginButton_click(event) {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginButton”).label = “Login”;
$w(“#profileButton”).hide();
} );
}
// 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("Members") 
      .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("Members", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 
    } 
    // update buttons accordingly 
    $w("#loginButton").label = "Logout"; 
    $w("#profileButton").show(); 
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}
}

export function profileButton_click(event) {
wixLocation.to(/Members/${wixUsers.currentUser.id});