Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a new user is already in the database #30

Open
jamiecoe opened this issue Oct 31, 2019 · 0 comments
Open

Check if a new user is already in the database #30

jamiecoe opened this issue Oct 31, 2019 · 0 comments

Comments

@jamiecoe
Copy link

When a user tries to sign up, you are not checking if they are signed up already.

You could do this by querying the database first to check if the user already exists.

Eg:

databaseConnection.query(`
    SELECT CASE WHEN EXISTS(SELECT email FROM users WHERE email = $1) THEN CAST (true AS BOOLEAN) ELSE CAST (false AS BOOLEAN) END`, [email], (err, res) => {
      const doesUserAlreadyExist = res.rows[0].case
      if (err) cb(err);
      else cb(null, doesUserAlreadyExist);
    });

This is nice because the query will give you a boolean, which you can use to decide whether the user is signed up already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant