Good question, yes you can! This one deserves its own video. I have a couple of videos already lined up to create but I will put this on my list to make. Thank you for the input.
Is there a way to easily make this session cookie store global? And also making the middleware global to use it for multiple routes over multiple controllers/handlers?
The session cookie is stored on the user's machine in the browser they are running. This cookie will be sent with every request (this domain only), so any of our handlers could check to see if this cookie is valid. This is as long as the cookie has not expired yet. I hope I am answering your question in that it is "global" in the sense that all the handlers (in your domain only) can have access to it when a request comes into the server. The middleware can be used for multiple routes, inside of the http.HandleFunc(, ) you will need to use http.HandleFunc(, Auth()). You will just have to pass your handlers into the middleware you want to run, in this case it was our authentication middleware named Auth() . This is nice since you can easily add middleware to the routes you want. You can also create other middleware functions for things other than authentication should you be inclined.
Amazing 🔥🙏
Thank you :)
Very useful video again! I can see the bright future of your channel in the days of Go's bright future! Jesus bless you man!
Thank you, will try to keep them coming :)
Great explanation! What if we want to decode the JWT token in the middleware, and pass a few values to our handler?
Good question, yes you can! This one deserves its own video. I have a couple of videos already lined up to create but I will put this on my list to make. Thank you for the input.
Is there a way to easily make this session cookie store global? And also making the middleware global to use it for multiple routes over multiple controllers/handlers?
The session cookie is stored on the user's machine in the browser they are running. This cookie will be sent with every request (this domain only), so any of our handlers could check to see if this cookie is valid. This is as long as the cookie has not expired yet. I hope I am answering your question in that it is "global" in the sense that all the handlers (in your domain only) can have access to it when a request comes into the server.
The middleware can be used for multiple routes, inside of the http.HandleFunc(, ) you will need to use http.HandleFunc(, Auth()). You will just have to pass your handlers into the middleware you want to run, in this case it was our authentication middleware named Auth() . This is nice since you can easily add middleware to the routes you want. You can also create other middleware functions for things other than authentication should you be inclined.
@@GrowAdept great explanation thank you!
No problem
Thanks
Welcome