Managing Login and Understanding JWTs
Learn how to use JWT tokens for secure authentication and authorization.
We'll cover the following
JSON Web Tokens (JWTs)
JSON stands for JSON Web Token, which is an open standard for exchanging security information between a client and a server. A cryptographic algorithm signs these tokens to ensure that the information cannot be changed after the token is issued.
In this lesson, we’ll go over how to create a login endpoint and how tokens are generated when a user successfully logs in. These tokens contain user-relevant data and can be saved throughout the app.
So let’s see what happens when a user tries to sign up.
On login, we ask the users to provide their
email
andpassword
.When they enter these details, we’ll run a check to see if their identity exists in the database.
If it does, we see if the
password
entered matches the one in the database.If it doesn’t match, they will be denied access; if it does, they will be granted access.
When a user logs in, we’ll also return a status code, their user information, and a token that will be required as a header in other secure endpoints.
Login endpoint
Two further functions—UpdateTokens
and ValidateToken
—need to be added to our tokenHelper
file. The validate token determines whether the passed token is valid or expired. The user’s token is simply updated by the update token function.
Get hands-on with 1400+ tech skills courses.