Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May also need extra user information but not just the token #243

Closed
yarcowang opened this issue Apr 20, 2020 · 4 comments
Closed

May also need extra user information but not just the token #243

yarcowang opened this issue Apr 20, 2020 · 4 comments

Comments

@yarcowang
Copy link

yarcowang commented Apr 20, 2020

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.

@mclxly
Copy link

mclxly commented Oct 17, 2020

My Solution:
`
c.Set("UserData", user)

...

user, exists := c.Get("UserData")
`

@Veerse
Copy link

Veerse commented Oct 18, 2020

My Solution:
`
c.Set("UserData", user)

...

user, exists := c.Get("UserData")
`

Works well, I've put c.Set() more precislley in Authenticator

@colonelpopcorn
Copy link

That's a good solution, and it may be good enough to close #195. Thoughts @appleboy?

@appleboy
Copy link
Owner

@colonelpopcorn Yes, Thank you for reminding me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants