Log in check

I’m trying to code that if you are logged in you go to a page, else you have to log in. I have the “if” part for if you’re logged in, but what is the “else” part?

this is what I have:

$w.onReady( function() {
$w();import wixLocation from 'wix-location';
$w();import wixUsers from 'wix-users';
$w('#CLicktostart').onClick ( () => {
    if(wixUsers.currentUser.loggedIn) true {
        wixLocation.to("Het spel");
        }
    else()

Hello,

looking onto your code, i can immediately recognize that you are not an experienced JS-Coder. Your CODE won’t work like that.

Why?

  1. You have a lot of SYNTAX-ERRORS
  2. Completely chaotic code-structure (code without order)
  3. You use depricated API → Wix-Users (old one)

So how to make it the right way?

https://www.wix.com/velo/reference/wix-members

import wixLocation from 'wix-location';
import { currentMember } from 'wix-members';
    
$w.onReady(function () {
    let options = {fieldsets: ['PUBLIC'],};
    currentMember.getMember(options)
    .then((memberInfo) => {console.log('currentMember.getMember', memberInfo);})
    .catch((error) => {console.error(error);});
});

In your console, you should get some data like the following…

Thanks!
indeed, I’m new to Js-coding. Thanks for your fast reaction!

1 Like