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

Force Unique user in SQL database #33

Open
samjam48 opened this issue Aug 16, 2019 · 2 comments
Open

Force Unique user in SQL database #33

samjam48 opened this issue Aug 16, 2019 · 2 comments

Comments

@samjam48
Copy link
Collaborator

You can add a UNIQUE specifier in your SQL database to prevent multiple occurrences of the same username. This would save having so much logic in the handleRegister() function and allow you to make the code more efficient without polling the database to find all users and then see if they exist already.
(although nice job on implementing all this functionality and making it work)

Your SQL would just be like this:

CREATE TABLE IF NOT EXISTS users (
    user_id SERIAL PRIMARY KEY,
    user_name VARCHAR(50) NOT NULL UNIQUE,
    user_hash VARCHAR(100) NOT NULL
);

and then why you try and add a user you can just handle the error if the user exists instead of so much code for verifying stuff.

@samjam48
Copy link
Collaborator Author

You could use the functionality you've built to check in the front end to prevent the form being submitted and send them an error message if the username is not unique

@gminova
Copy link
Member

gminova commented Aug 16, 2019

thank you! 😸 didn't know about that,

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

2 participants