SS.95, here some further info.
To help, here is what is what the codes does, that you were given.
- when the web page loads, it calls the onReady function (javascript code), after loading
- the onReady() function calls the WixUsers.onLogin function, the onLogin function returns a user object.
- the user object, contains several properties (variables), and methods (functions)
- the user.getEmail() method is called and it returns an email variable containing the email.
- the .then() waits for the email variable, and continues processing once it gets it
- the first WixData query, takes the email and looks in the ‘HasLoggedIn’ collection(table), to see if the user’s email exists in the table.
If the user exists, then there will be a record containing his/her email, and the results.items.length will be >0.
If the results.items.length is 0 ( ==0), then the record does not exist, therefore this is a new user who never logged in. - the first if (==0) section deals with the new user, whose never logged in before:
i) a new record is inserted into the ‘HasLoggedIn’ collection, containing the new email
ii) the page is then directed to a page for the new user, you need to change this to yours - the elseif, checks if there is at least one record in the ‘HasLoggedIn’ collection (table).
i) if there is at least 1 ( >0), then this user has logged in before because a record exists with his email.
ii) the user’s roleName is fetched from the ‘user.getRoles()’ function(method).
iii) the next if, checks the roleName to confirm if the user belongs to ‘role1’, and if he/she does then they are forward to to the ‘/page1’ link.
iv) the next elseif, checks if the user belongs to ‘role2’. If they belong to role2, then they get forwarded to the ‘role2’ page
There seems to be some pieces of missing info you got, that needs to be resolved.
-
It looks like you will need to create a ‘HasLoggedIn’ collection(table) using the Content Manager. It needs to contain a field called ‘userEmail’. the naming of the field is important (case sensitive). The program won’t work if the name is not correct. The permissions of the collection should most probably be set to ‘Form Submission’
-
If you don’t care about the roles, just if they have logged in, then you get rid of lines 29-36, and replace those lines with a single line: wixLocation.to(“/page1”); [remember you need to change /page1, to your actual page].
Hope this helps you move forward.