The way you are interacting with the project is so good, explaining each and one thing is very recommendable, hope you will bring much more projects soon
I have just gone completed this and it works great! I followed the video checked the app at same points, this allowed me to catch any self made errors as I went. This is one of best introductions to this topic I have found on the web which isn't behind a paywall! I have learnt a lot from this video and will be watching more from this channel! Thankyou!
and just one minor suggestion is to add the admin auth too, and email confirmation for signup and password lost. Also good idea to use something like express validator package.
after logged in successfully when i refresh page No routes matched location "/user" and can u help me how can i implement /config on sails js project (config/session.js) and how to remove or modify sails autogenerated cookie named sails.sid
It's a good idea, but it just increases network requests. Is it possible to control the network request with this idea when dealing with production applications? 💡
If we just delete our req.cookies in refresh token handler, then how in this world we are supposed to get it in our verify token handler just after deleting it.
1. same site has a default value of lax 2. what's the point of using cookie-parser if you are accessing headers.cookie and splitting it using = as delim 😐 should have accessed cookies json object from req.cookies
are you talking about provider and store in redux ? to make the data of the store available to the entire components, we have to wrap our main component that wraps all other components inside the provider component and pass the store as a value to the provider component. while the store is a central part where we store our data that needs to be updated and it is available to the entire app.
in sing in if an account was already exit it will give an error and user will not know what is happened .! question: how to handle msg between backend and frontend
On signup token is not generated and throws error invalid token also showing this (Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client)
hi again! if I set the token expiration for 1 day, do I still need to do the refreshing token routes? I find that refreshing every 30 seconds is a bit too much burden on network request, I like the cookie idea, but refreshing route is a bit burden though for users, especially for ecommerce site, I mean people need to keep refreshing their webpage while shopping can be annoying, no?
what happen when user refresh the page before 28 sec will the timer of setTimeout function will restart and then token has expired before hitting the refreshToken api.if token has expired before hitting the refresh token api then how u can get the id of user from the token and how u can get the details of the user without that id that uses getUser api??????
do i have to write this axios. /refresh code on every page after login i mean i have multiple pages a complete dash board, so do i have to add it to all the pages?
I'm a bit confused on the token/cookies. I have it all set up, but if I want to go to another Route/Component - how do I get the user object to carry on? Whenever I go to a new URL, the cookie/token are gone? How do I access it across my app? I think I'm confused about some fundamentals here.
The goal is to allow a user to login, and from there they are shown the services available to them. And as they click a new page, it is rendered to show their info (i.e. Hello, Name).
It's already implemented there to move to a different components like welcome page. Maybe you are doing something wrong. Please check source code and see where it went wrong
@@IndianCoders So I figured it out. My question is - do I have to call the getUser on every component in order to fetch the user? And do I have to implement the refresh token on every component?
first time its working. again i try with new user signup, i dont know why it happens to me only, its not workig. postman says signup please. even when i copied everything correct, checked, re-checked, its not workign for me. i am leaving full stack, it not for me. goodbye
Hi if you are looking this comment please reply to me or anyone can help its necessary I have followed your tutorial and make project everything is been fine and cool but problem is that when I logged in it display me user information but when I refresh that page all information gone I tried each and everything but nothing works, can you guide me which part of code I have to change to stop that behavior and user data remain in page even If I refresh The page
@@doruktekel3438 ahaha I am here for you, actually bro his technique and implementation is very poor that creates so much problems and plus he is not storing cookie properly with am mechanism of time duration, I will recommend you to instead of jwt, use express session technique with bcrypt library and when user sign in a session is been created for all necessary things you have governed user name..email or phone... And from that session you will display that in to user profile and it's easy to implement too.
Please help me.Browser (postman) create two cookies : 1 for auth, other is "refreshToken" automatically. And split('=')[1] dont work because cookies have a two tokens. Google didnt help. How can I delete this "refreshToken"?
Hi. I think the problem is, before creating refresh token, make sure to check if cookies are already there for that ID. If it's there, delete that cookie's value and you can also clear that cookie from res.clearCookie() function. And then refresh token will work fine. And for the auth, you can restart the server and make a fresh auth request but before sending request make sure you are not already in welcome page because from there it'll send request with use-effect. You can move to login route again and check. Check if this solution works. And I'll upload the source code for this tutorial today itself . And let me know if it's fixed. 😊
The concept is good but after refreshing the page, why the refreshToken is not working why the prevToken is expired after refreshing .. is it because the setInterval() reset everytime we refresh the page?. Any solution?
const VerifyToken = async (req, res, next) => { const cookies = req.headers.cookie; if (!cookies) { return res.status(401).json({ message: 'Error not found' }); }
const token = cookies.split('=')[1]; JWT.verify(String(token), process.env.SECRECT_key, (err, decoded) => { if (err) { return res.status(400).json({ message: 'Invalid Token' }); } // Doing this because what if they refresh after login because setInterval Reset res.clearCookie(decoded.id) req.cookies[decoded.id] = ''; const token = JWT.sign({ id: decoded.id }, process.env.SECRECT_key, { expiresIn: "35s" }) // console.log('REGenerated Token ', token) res.cookie(String(decoded.id), token, { path: '/', expires: new Date(Date.now() + 1000 * 35), httpOnly: true, sameSite: 'lax' }); // Doing this because if they refresh after login because setInterval Reset
req.userId = decoded.id; next(); }); }; This works if i regenerate token in VerifyToken again for the refresh problem. Idk Whether this is a good approach.
Giving Empty github repo is not called giving source code . Please don't make us fool nobody is dumb bro !!!!! , and Please share the code it's a humble request.
the time i started using cookies in the project, postman stopped giving any output. It kept loading and loading for about 2 hrs. What must be the error here?
If you are not getting cookies in node js . set sameSite = none and scure = true in res.cookie res.cookie(String(user._id), token, { path: '/', expires: new Date(Date.now() + 1000 * 30), httpOnly: true, sameSite: 'none', secure: true })
how to solve this error-: Cannot read properties of undefined (reading 'data') TypeError: Cannot read properties of undefined (reading 'data') at sednRequest (localhost:3000/main.b32a4075083886843b25.hot-update.js:42:28)
I haven't seen the your full video but the "technologies will be used" overview gave a really great feel and I know that this is "actually" advanced
This is an amazing video and helped me out exactly with my project. Keep up the work, you've really taught me a lot.
When I refresh the page the reference router the refresh token function throw an error like cookie.split the cookie is undefined
The way you are interacting with the project is so good, explaining each and one thing is very recommendable, hope you will bring much more projects soon
I have just gone completed this and it works great! I followed the video checked the app at same points, this allowed me to catch any self made errors as I went.
This is one of best introductions to this topic I have found on the web which isn't behind a paywall! I have learnt a lot from this video and will be watching more from this channel!
Thankyou!
Thank you for sharing your knowledge. I, perhaps for the first, fully understand the process of authentication as a self-learner. Many thanks!!
Wonderful!
Greate Course! 😍
wow this is the best mern auth out there! great work indian coders, I learned a lot especially cookier parser!
and just one minor suggestion is to add the admin auth too, and email confirmation for signup and password lost. Also good idea to use something like express validator package.
Thanks for the suggestion, will look into it
Facing problem 'undefined'by logging to the console the COOKIES
Please hel
dhnyawad bhai ........bahot hi badiya kaam
wow. good and most wanted video. But i feel , in future videos pls do coding with ES6.
Sure will do with ES6 in Nodejs. And we have upcoming projects on MERN too 😊
Please add forget password session in this part 2 by email confirmation
Very Clear. Thank you
thank you yr seriously a lot of help from your toturials thank you so much
Thanks. Please support this channel by sharing on your social media.
no we can use it with fetch also. in case of axios we can use withCredentials:true and in case of fetch we can use credential:'include'
Nice video from Karachi
Thanks for describing in such a great way!!!!
I learnt a lot
after logged in successfully when i refresh page No routes matched location "/user" and can u help me how can i implement /config on sails js project (config/session.js) and how to remove or modify sails autogenerated cookie named sails.sid
when refreshing page and logging again there is an error which the user is undefined when verifying token in verifyToken function
mine vscode is not showing suggestions of mongo models, or the cookie part, how to fix it?
thankyou so much i really learned new thing today
Please support by sharing and subscribing
It's a good idea, but it just increases network requests. Is it possible to control the network request with this idea when dealing with production applications?
💡
Thank you for this
I think better approach would be creating separate Refresh Token, Will you make one Video for us? Thanks a lot
I am happy to the name of you tube
If we just delete our req.cookies in refresh token handler, then how in this world we are supposed to get it in our verify token handler just after deleting it.
i am getting value of cookie undefined
Same for me
Same here bro
Thank You so much for this amazing vedio
nice thank you so much
good bro keep it up
Good one
Thank You @Dhinesh
Hey bro! I am not able to stay logged in after refreshing the page
Have u correctly followed the approach?
Please check with backend first and then try it on frontend
I am not able to stay logged in after refreshing page...and i have checked your code and it's behave the same
cookies are not being sent even the withCredentials are true in axios
please provide any solution for this
code is not working it is getting (Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client) and token is not valid
Bro just se your controllers and remove multiple return statements
1. same site has a default value of lax
2. what's the point of using cookie-parser if you are accessing headers.cookie and splitting it using = as delim 😐 should have accessed cookies json object from req.cookies
how to protect routes in react ?you not covered yet
I've added it in the courses. As of now they are just conditional protected routes but you can implement it in another class and use that
Hi Sir,
can you show us how to persist loginState after logging in on each refresh???
Plzzzz
Thank you in advance.
Good stuff, really helpful. If you could talk a bit slow it would be awesome. Thanks!
cookie not being set to the browser Application area yet it can be found in the response headers after login. Can you plz help with that
great bro
Thank you♥️
@@IndianCoders completed just now ♥
After deployment browser is not setting cookie what to do now
thank you bro
wow thanks bro
hello, i have learnt so much from your video, but will you please explain clearly about "provider" and "store"...
are you talking about provider and store in redux ? to make the data of the store available to the entire components, we have to wrap our main component that wraps all other components inside the provider component and pass the store as a value to the provider component. while the store is a central part where we store our data that needs to be updated and it is available to the entire app.
Which key u used to import login, signup, welcome ???
On refreshing the page after login I am getting logged out 🤕
Because of redux reset the value of logged in need to persist using redux persist
if i do code with you then am i facing any problem as it is old content
in sing in if an account was already exit it will give an error and user will not know what is happened .!
question: how to handle msg between backend and frontend
You can send messages from backend, but in the end we checked it with already logged in user. Please check again what's wrong
1 hour and 57 minutes watched
When I refresh the page the reference router the refresh token function throw an error like cookie.split the cookie is undefined
same
hey thanks for the amazing video! but after logging in, if i refresh the page it logs out automatically why so?
On signup token is not generated and throws error invalid token also showing this
(Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client)
I had the same issue too after signing in
Same for me
Same
hi again! if I set the token expiration for 1 day, do I still need to do the refreshing token routes? I find that refreshing every 30 seconds is a bit too much burden on network request, I like the cookie idea, but refreshing route is a bit burden though for users, especially for ecommerce site, I mean people need to keep refreshing their webpage while shopping can be annoying, no?
You can check refreshing time for 1 hour or a day as well.
will the user have to login again the next time he visits? or will it remain login for the next time as well.
The jwt token get's verified everytime even after changing the token intentionally
Facing error 'undefined' by logging console to the COOKIE
PLEASE HELP ME
thanks Nikhil
what happen when user refresh the page before 28 sec will the timer of setTimeout function will restart and then token has expired before hitting the refreshToken api.if token has expired before hitting the refresh token api then how u can get the id of user from the token and how u can get the details of the user without that id that uses getUser api??????
same
do i have to write this axios. /refresh code on every page after login i mean i have multiple pages a complete dash board, so do i have to add it to all the pages?
I'm a bit confused on the token/cookies. I have it all set up, but if I want to go to another Route/Component - how do I get the user object to carry on? Whenever I go to a new URL, the cookie/token are gone? How do I access it across my app? I think I'm confused about some fundamentals here.
The goal is to allow a user to login, and from there they are shown the services available to them. And as they click a new page, it is rendered to show their info (i.e. Hello, Name).
It's already implemented there to move to a different components like welcome page.
Maybe you are doing something wrong. Please check source code and see where it went wrong
@@IndianCoders So I figured it out. My question is - do I have to call the getUser on every component in order to fetch the user? And do I have to implement the refresh token on every component?
@@IndianCoders
can you please tell me what I need to do?????
first time its working. again i try with new user signup, i dont know why it happens to me only, its not workig. postman says signup please. even when i copied everything correct, checked, re-checked, its not workign for me. i am leaving full stack, it not for me. goodbye
Can you find code on GitHub to check if it works
getting cookie is 'undefined' error. Noit sure how to fix it
does anybody had repo which is in this repo
why did you delete the source code from GIT?
after i login, i refresh , error occur, may be this is a bug, i want when i refresh, we still in user page
Im getting error while hashing illegal arguments ; number, string
req.cookie is undefined why??this error
Sir please make a video on multiple user roles
Coming with a major project
@@IndianCoders thank you so much sir 🙏
nice video but how fix this error please
'ERR_HTTP_HEADERS_SENT'
Can you please share the full error and when you are getting this error and in backend or frontend?
@@IndianCoders in this part ( Creating Frontend - Adding Welcome User Page and Sending axios request with withCredentials property)
Hi if you are looking this comment please reply to me or anyone can help its necessary I have followed your tutorial and make project everything is been fine and cool but problem is that when I logged in it display me user information but when I refresh that page all information gone I tried each and everything but nothing works, can you guide me which part of code I have to change to stop that behavior and user data remain in page even If I refresh The page
same
@@doruktekel3438 ahaha I am here for you, actually bro his technique and implementation is very poor that creates so much problems and plus he is not storing cookie properly with am mechanism of time duration, I will recommend you to instead of jwt, use express session technique with bcrypt library and when user sign in a session is been created for all necessary things you have governed user name..email or phone... And from that session you will display that in to user profile and it's easy to implement too.
hey sir after login showing user not found can u send github source code link
bro he share source code , yon can change branch in github source code
sir, same step i have followed using next js. not working.
What happened?
hey, its not working for me :( whats the packages i need to install?
Check package json file in GitHub branches
Please help me.Browser (postman) create two cookies : 1 for auth, other is "refreshToken" automatically. And split('=')[1] dont work because cookies have a two tokens. Google didnt help. How can I delete this "refreshToken"?
Hi. I think the problem is, before creating refresh token, make sure to check if cookies are already there for that ID. If it's there, delete that cookie's value and you can also clear that cookie from res.clearCookie() function. And then refresh token will work fine. And for the auth, you can restart the server and make a fresh auth request but before sending request make sure you are not already in welcome page because from there it'll send request with use-effect. You can move to login route again and check.
Check if this solution works. And I'll upload the source code for this tutorial today itself . And let me know if it's fixed. 😊
@@IndianCoders thx Man, I will try
@@IndianCoders Used res_clearCookie('refreshToken') once. It solved my problem
@@nalcapital great 👍😃
Bro I have issues with login route in backend can u post the code in your GitHub??
branches
would be best if you give the source code please ;(
thanks for tutorial btw this is really awesome!!
Will try to post
Great Video! Where is the source code?
Will be added soon 🔜
please dont command instead request
@@vc7deo Sorry :)
i wish you had the source code, much easy to follow up
Added
@@IndianCoders Seems removed again?
The concept is good but after refreshing the page, why the refreshToken is not working why the prevToken is expired after refreshing .. is it because the setInterval() reset everytime we refresh the page?. Any solution?
Looking into it
@@IndianCoders Aye why did you delete my comment in that other guys reply 😂. Bruh dont worry about it, everybody makes mistakes.
const VerifyToken = async (req, res, next) => {
const cookies = req.headers.cookie;
if (!cookies) {
return res.status(401).json({ message: 'Error not found' });
}
const token = cookies.split('=')[1];
JWT.verify(String(token), process.env.SECRECT_key, (err, decoded) => {
if (err) {
return res.status(400).json({ message: 'Invalid Token' });
}
// Doing this because what if they refresh after login because setInterval Reset
res.clearCookie(decoded.id)
req.cookies[decoded.id] = '';
const token = JWT.sign({ id: decoded.id }, process.env.SECRECT_key, { expiresIn: "35s" })
// console.log('REGenerated Token
', token)
res.cookie(String(decoded.id), token, {
path: '/',
expires: new Date(Date.now() + 1000 * 35),
httpOnly: true,
sameSite: 'lax'
});
// Doing this because if they refresh after login because setInterval Reset
req.userId = decoded.id;
next();
});
};
This works if i regenerate token in VerifyToken again for the refresh problem. Idk Whether this is a good approach.
error handler TypeError: Cannot read property 'split' of undefined ??
how can I solve that issue ?
Maybe the token is incorrectly set. Check in source code
@@IndianCoders it's worked on postMan, but on react it's dosnt set the cookie
i have gotten error "can not read undefiend property 'user' at about.js" deploying the site
What's the error?
@@IndianCoders can not read undefined property 'user' at about.js
@@IndianCoders sir please make a video on how to deploy that site
where is the source code
source code is empty
Check branches
@@IndianCoders thankyou for your contribution to this community this is very helpful
Giving Empty github repo is not called giving source code . Please don't make us fool nobody is dumb bro !!!!! , and Please share the code it's a humble request.
Have u checked branches 🙃
@@IndianCoders Yeah got it. I never saw someone putting it like that way. Anyway Thanks a lot mate !!
Hello sir please deploy this website i have so many errors at deploying time
Great tut! but code pls? github empty
go to branches
@@Seedley Thanks!!
ye video achanak kaha gayab hogai thi
Hmm because I am about to push another one with more features such as admin, reset password etc
@@IndianCoders to kabtk ajayegi
Hey is this React or React Native?
React
the time i started using cookies in the project, postman stopped giving any output. It kept loading and loading for about 2 hrs. What must be the error here?
Check error in console. And let me know
@@IndianCoders it worked thank you so much for this tutorial
Can I get the source code please?
Yes. It's there in description.
@@IndianCoders no its not in the description,,, please check again.
please deploy this project
Don't watch this doesn't work I spent lot of time and it was waste
it works well. are you stuck somewhere?
If you are not getting cookies in node js . set sameSite = none and scure = true in res.cookie
res.cookie(String(user._id), token, {
path: '/',
expires: new Date(Date.now() + 1000 * 30),
httpOnly: true,
sameSite: 'none',
secure: true
})
how to solve this error-:
Cannot read properties of undefined (reading 'data')
TypeError: Cannot read properties of undefined (reading 'data')
at sednRequest (localhost:3000/main.b32a4075083886843b25.hot-update.js:42:28)