Help with code

I have a button that is working fine. When I click on it, it look if I am log in. If yes, no problem, if no, then the piece of code that is contained in the ELSE section is working only half.

You can see below the code that is working and the code that is not working in YELLOW.
I am pretty sure it’s something very dumb but I can’t find my mistake. so the code is working as it prompt you for login, then it look if the user exist already, if the user does not exist, then it create the user in my database. then come the part that does not work… it should redirect the user to a page depending if the field usertype is = to members or friends + it should rename the button called menuprofil.

Can someone help me ?

p.s : all the field names and page names are good as I have double check everything.
thanks :slight_smile:


I think this if “if (results.items.length === 0)” is missing an else block, meaning the whole redirect logic will try to run even if there are no results, meaning the user is not in the database.
This code will probably fail because in the case of no results, you’re trying to access the first item in the results and will get “undefined”.

Does that help in any way?

Side note, we now support a new syntax for using promises called “async await”, it can make your code more readable. You can read about it here: JavaScript Async/Await Explained in 10 Minutes - Tutorialzine