May also need extra user information but not just the token
yarcowang opened this issue ยท 4 comments
I'm using github.com/appleboy/gin-jwt/v2 v2.6.3
Part of the Authware definition is like this:
LoginResponse: func(ctx *gin.Context, i int, s string, t time.Time) {
ctx.JSON(i, gin.H{
"code": i,
"data": s
})
},
It seems you suppose user want the token as the data
for there's no way to get user
information.
Though, as a backend developer, I can get everything I need, the frontend may also need something else (like roles/permission to show/hide something, which I don't want to do another query because during the step of Authenticator
, I already get the user
).
So, I think this callback may can be defined as LoginResponse: func(ctx *gin.Context, i int, s string, u interface{}, t time.Time)
so that, I can get other information returned.
My Solution:
`
c.Set("UserData", user)
...
user, exists := c.Get("UserData")
`
My Solution:
`
c.Set("UserData", user)...
user, exists := c.Get("UserData")
`
Works well, I've put c.Set() more precislley in Authenticator
@colonelpopcorn Yes, Thank you for reminding me.