VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
What are JSON Web Tokens? JWT Auth Explained [Tutorial]

What are JSON Web Tokens? JWT Auth Explained [Tutorial]

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Learn about JWT and how to use them for authentication. JSON Web Tokens are used for representing claims securely between two parties. In this tutorial , you will learn the JWT Auth flow without being distracted by a lot of extra libraries. This tutorial teaches JWT Auth as simply as possible. - Code: https://github.com/weibenfalk/jwtToken-react-express - Video from Thomas Weibenfalk. https://www.youtube.com/channel/UCnnnWy4UTYN258FfVGeXBbg
Date: 2022-03-14

Comments and reviews: 7


Hello -freecodecamp
Thanks for ur interesting and best remarkable courses you provide
but during using the refresh token to create new accesstoken, on frontend for me once I refresh the it takes me back to the login page
just help me to solve that thanks best regards
Here is my endpoint for the refreshtoken
app.post(-/refresh_token-, async (req, res, next)=>--
const token = req.cookies.refreshToken;-
//if there is no token-
if(!token) return res.json(-accessToken: ''-);-
//if we have token-
let payload = null;-
try --
payload = jwt.verify(token, process.env.REFRESH_TOKEN_SECRET);-
- catch (error) --
return res.send(--
accessToken: ---
-)-
--
//let's find the user-
let user = await User.findById(payload.userId);-
if(!user) return res.json(-accessToken: ---);-
if(user.refreshToken!==token) return res.send(-accessToken: ---)-
let accessToken = createAccessToken(user._id);-
let refreshToken= createRefreshToken(user._id);-
user.refreshToken = refreshToken;-
sendRefreshToken(res, refreshToken);-
return res.send(- accessToken -);-
-)

reply

I never comment a video before, but I do it only for FCC, you are the light of a dark time, I'am sorry for not being able to make a donation, I live in a country where the online payment card are forbidden , where the technology and learning are just for governor's sons and the rich people , thanks you for the knowledge and you gave me hope after having lost you are the best school that I never could have with teachers that I never knew IRL, I'm sorry for not being able to make a donation, one day I will be the best,
free camp code --dear guardian of science

reply

I learned a LOT from this tutorial! Not just about tokens. I learned about other things I'm new to: REST, React, CSS, HTML. Even things that were NOT explicitly part of the course I learned about: e.g. cool VSCode shortcuts. I couldn't figure out how to use POSTMAN so I was forced to figure out how to use cookies with cURLs! All super-valuable! I will definitely seek out other courses by this instructor.
reply

If iam logged in a website through auth redirect url token in one browser and again if iam logged in the same website in another browser, it creates another different url token for login . Then which url token will be registerd or tracked by that website ? either First one or next one..?? Thankyou for ur valuable answer in advance..!!
reply

Hi,
After log out, when I will use old access token (which should be invalid, from backend point of view), I'm taking protected data. Is it something missing in the tutorial? Or that is all well known and anyone should add next level for checking access token before returning protected data?
Or, this is how it should works?

reply

Hello, In my refresh_token route, My token is successfully set, but when i'm trying to request it. And im console.log it out. it return undefined? How can i solve this please
reply

How to persist the authenticated state after a page refresh?
No GET api/url performed to refresh the token, just hit F5
Edit: use a refreshToken

reply
Add a review, comment






Other channel videos