Why are we deleting the jwt token from the database. It was created when the user registered that device right? Then on logout ideally shouldn't the user be able to directly login to the application, instead of again registering himself? Also why are we storing the token in the database, when we are just comparing the login's jwt token with the SECRET_KEY?
@ayu_slayss No, I didn't receive any answer. But what I find out myself is that ideally there is no need for storing a jwt token during registration. Jwt token should be temporary and should be generated at the time of login. Then, while accessing different routes, there should be an authVerify middleware that would ensure the validity of the token before every page visit/api hit.
i don't understand how does removing the tokens logout the user as ...we are authenticating using verfiy to authenticate the user and not verifying token in the cookie===token in database... and also verify just returns the id of the user which has nothing to do with database ....
@@nitishverma7275 i am no pro... but one way is using handlebars where you can use if else ...read more here about using if else and other logic in hbs files (handlebarsjs.com/guide/builtin-helpers.html#unless) Then you can do like {{#if somevar)}} html code for signin and signup so when you want to show login just send {somevar : true} from your app.js and when you render a secret page then send {somevar:false } then that part wont render and you won't see the button if you don't understand learn how to use template engine (any) to send variable (if you already don't know😂)
Dear in case of single user logout , the token is generated based on userid so same token is generated every time login, so when try to delete that tokon from db then all token are deleted so please may you suggest me how to generate different token for same user id while every login????
How can we use req.user globally in a get function without passing "AUTH"middleware E.g app.get(''/check',(req.res)=>{ if (req.user){ res.send('REQ.USER IS IN REACH') }else{ res.send('PLEASE LOGIN TO VIEW THE MESSSAGE') } Please iska hall bata dein
If someone copies the token after login and simply logout and after logout he is trying to access any page using that token in this case how we can handle it.
What if user doesn't logout and the cookie expires, then the cookie will be deleted from the browser but the tokens which are created will remain in the database. How shall we delete those tokens in this case ? Please explain.
Thank you so so so so much vinod sir. You've helped me a lot in making my project. Can you please make a video on how to make admin panel with its backend ? I'll be really thankful
when i logout my cookie is not getting clear even thought i used res.Cookie("jwt") method but if i refresh again than its showing jsonwebtoken required error anybody knows how to fix it ?
This was indeed an extremely important tutorial. However, I'd like to do one thing. By default, the Logout button won't be visible. When the user logs in, then the Logout button will be visible and the Login button will disappear. Again, when the user logs out, the Logout button will disappear and the Login button will be visible. How can I do it? Any help on this issue is highly appreciated. Please suggest.
Sir ji res.ClearCookie("jwt") karne k bad req.user.save() kyu kia ??. A toh sirf browser par jo cookie stored tha usi ko hi clear karna tha na??? Db ka cookie ko toh clear nahi karna tha. Toh req.user.save () kyu kia?? Hamko a samajh nahi a raha. Par db and browser par jo cookie tha usay filter out karke return karne k bad jo req.user.save() kia wo samajh may aya.
hello sir please make a very small project of nodemailer with react and teach us how to connect node js express js and mango with react in hindi please sir
Can we add sign up with Google and Facebook in nodejs like you did in php MySQL tutorial also can we add verification email and remember me in node js like PHP MySQL tutorial. If yes then will you make videos on them in this series. Please reply. One last question should I learn php or nodejs . I'm a 10 class student and I know basic javascript HTML5 CSS3.
@@sauravrijal5855 bro he is asking email verification in nodejs & mongodb not php. Vinod bhai already did email verification of php, he is asking the same for Nodejs and mongodb.