Skip to content

How to properly setup JWT tokens with TEMPL and Echo (noob) #2677

Closed Answered by jramiroz98
jramiroz98 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello handsome guy! I just found your solution!
This works just fine:

func loginGET(c echo.Context) error {
	user := c.Get("user").(*jwt.Token)
	claims := user.Claims.(*jwtCustomClaims)
	name := claims.Email
	println(name)

	return Render(c, http.StatusOK, templates.Login())
}

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):


// Create a cookie
	cookie := new(http.Cookie)
	cookie.Name = "JWTToken"
	cookie.Value = t
	cookie.Expires = time.Now().Add(time.Hour * 72)
	cookie.HttpOnly = true
	cookie.Secure = true // Ensure this is true when serving over HTTPS
	c.SetCookie(cookie)
	return c.JSON(http.S…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jramiroz98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant