How to properly setup JWT tokens with TEMPL and Echo (noob) #2677
-
Hello there, I'm not very proficient with Go and I'm trying to learn while building a small project.
Yet I get an error saying
I would like to use the token later to redirect users from pages that they shouldn't use (like the login or register page, once they are logged in) or fetch their information (I have setup a sqlite db with their info) My experience vastly comes from using Sveltekit and good share of Python. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello handsome guy! I just found your solution!
Creating cookie with tokenWhat you need to do is make sure that you are creating your cookies properly! Do it like so (preferably at login):
If you don't add the previous settings to the cookie it wont work. Reading TokenTo read from the cookie you should use the following:
Middleware and configBy doing the previous line of code you get to add the cookie properly into the request before the call. This should be done by using middleware like so: Also, use:
This will read from the cookie and use the config BEFORE the route is called. Most people group it, so it's definitely recommended |
Beta Was this translation helpful? Give feedback.
Hello handsome guy! I just found your solution!
This works just fine:
Creating cookie with token
What you need to do is make sure that you are creating your cookies properly! Do it like so (preferably at login):