So I found this piece of code online however when I copied it into my website it just never works and I keep getting this error. Any help will be appreciated.
exportfunctionloginButton_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(); } );
}
export function loginButton_click(event) { //<---MISSING spaces between export function // user is logged in if(wixUsers.currentUser.loggedIn) { // log the user out wixUsers.logout() .then( () => { //<---------------------------------REMOVE this whole line // update buttons accordingly $w("#loginButton").label = "Login"; $w("#profileButton").hide(); } ); //<---------------------------------REMOVE this as well, now it won't wait for the promise! }
COREECTED:
export function loginButton_click(event) { // user is logged in if(wixUsers.currentUser.loggedIn) { // log the user out wixUsers.logout() whole line // update buttons accordingly $w("#loginButton").label = "Login"; $w("#profileButton").hide(); }
you found this answer most likely because you are trying to complete the following tutorial on YouTube by Wix Training Academy:
https://www.youtube .com/watch?v=dGZkTZYtFQs
You can help me by dropping a like a question and referencing me to answer it on stack exchange: https://www.stackoverflow .com/questions/ask
.then(() => { //SO I CAN ANSWER IT! @Chef_Code //I WILL I PROMISE! return https://www.stackoverflow .com/users/4799827/chef-code });
see https://www.wix.com/velo/reference/wix-users/logout
especially the line :
so get rid of the .then.