You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your getting so close! Creating a user works. Logging in works. You just need to connect them up together check the user exists and should be allowed to log in. Then add a log out option
Creating a user
Validation, as the user focuses out, is great.
You could add a similar function checkUser() to run on username field focusout to check if they exist in the database details, then display an error before they submit.
Once user is created and you get a success from the DB (try returning id if you like) then run the login function with the created users details to set a cookie and direct to the trivia page
Login allows any user
Currently, login allows anyone (Nice work on setting a cookie to keep them logged in).
You could pull the table to the front end and search through the users and check if username and password exist, but this would send the user all the details of your users and their passwords so not cool, keep this in your server and just send the user a cookie if they are legit.
Try and write an SQL query that finds a user where name and password matches. SELECT id FROM users WHERE name=_NAME_, pass=_PASS_;
(Or you could write two queries. One to check user exists. If does not exist show a not found user error. If they do exist run a second query to check password is correct for that user)
Logout function
create logout button on trivia page
create /logout route - call logout handler
create /logout handler - clear cookie and send to user to home page
The text was updated successfully, but these errors were encountered:
Your getting so close! Creating a user works. Logging in works. You just need to connect them up together check the user exists and should be allowed to log in. Then add a log out option
Creating a user
Validation, as the user focuses out, is great.
checkUser()
to run on username field focusout to check if they exist in the database details, then display an error before they submit.Login allows any user
Currently, login allows anyone (Nice work on setting a cookie to keep them logged in).
You could pull the table to the front end and search through the users and check if username and password exist, but this would send the user all the details of your users and their passwords so not cool, keep this in your server and just send the user a cookie if they are legit.
Try and write an SQL query that finds a user where name and password matches.
SELECT id FROM users WHERE name=_NAME_, pass=_PASS_;
(Or you could write two queries. One to check user exists. If does not exist show a not found user error. If they do exist run a second query to check password is correct for that user)
Logout function
The text was updated successfully, but these errors were encountered: