Sign up not working!

Hey!
I have a problem: when the users sign up to my website they are saved as new Members but their information is not saved to the collection…
What should I do?
Here’s the code:

import wixUsers from 'wix-users';
import wixData from 'wix-data';

export function button1_click() { 

 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("Company")
          .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("Company", toInsert)
            .catch( (err) => {
              console.log(err);
            } );
        }
        } )
      .catch( (err) => {
        console.log(err);
      } );
  }

Thanks!

Are you trying this in Preview or Live? You should note, that it’s stated in the wix-users API docs:
The APIs in wix-users are only partially functional when previewing your site. View a published version of your site to see their complete functionality.

If you are running this in Live, are you getting any messages in the browser’s Javascript console?

Not sure? Well, did you try the site in Preview or in Live? What is the difference between the company and user sign ups?

I tried on Live, not preview.

When a company signs up they have a boolean field that allows the website to recognise them as a company, so they have a different “welcome page” than users have.

Companies will be redirected to welcome-company where they can find lots of actions and users will be redirected to welcome-traveller, where they will be able to upload their information and nothing else.

The code you posted above is not correct. What I see in your code is that you do a redirect and then you attempt to open a Lightbox, but the page should have already redirected:

wixLocation.to(`/welcome-traveller`)
let userId;
let userEmail;
// prompt the user to log in 
wixUsers.promptLogin({ "mode": "login" })

You will need to correct the logic of your event handlers before the login process works correctly.

Yes I thought it was that but with the same code is working for companies and not for users… I think you are able to see my editor. I dont know why if they are the same but in 2 different functions (click one button or click another one)

Both buttons still have the redirect so the promptLogin never gets executed.

The users collection has different permissions than the company collection:

The users login should work if you change the permissions of the users collection.

Omg Yisrael… Thanks, I’m really sorry. What an obious mistake, fucking newbyyyyy hahaha sorry sorry, really :cry:

I changed the permissions and its working, it was not the redirection function TT

Thanks and sorry :frowning:

Hey Blai,

Don’t worry - how long did it take me to figure it out? sigh

Take care :beers: