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.
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
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 thehandleRegister()
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:
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.