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
How to Access specific values from claims interface{} #3
Comments
I was struggling with a similar problem (I'm also new to Go and still learning). In my case, I wanted to use the value of the email field, and after a lot of research, I was able to get it by using reflection. defer func() error {
err := recover()
if err != nil {
log.Println("Recover!: ", err)
}
return nil
}()
fu := c.Locals("user")
rfuv := reflect.ValueOf(fu)
rfuv2 := reflect.New(rfuv.Type()).Elem()
rfuv2.Set(rfuv)
rfuv = rfuv2.FieldByName("email")
rfuv = reflect.NewAt(rfuv.Type(), unsafe.Pointer(rfuv.UnsafeAddr())).Elem()
fuvstrptr := (*string)(unsafe.Pointer(rfuv.UnsafeAddr()))
fuvstr := *fuvstrptr
log.Println("User Email: ", fuvstr) I don't think it's a good solution, and I too would like to have something to access each field 😅 |
Hi sorry for late reply. some-reason i didn't see this open issue. You can try below method to access the context param 'user' and attribute values
thanks! |
Ah got it. Thanks for the help. |
This is more likely my lack of understanding of how Go works than a gofiber-firebaseauth specific problem.
In the examples it shows accessing the claims object from context and printing it out.
This works and I see this
From looking at the source, it loads in the private
user
struct into the context which is populated by fields fromToken
from firebase. This results in a genericinterface{}
for claims and I cannot figure out how to access each field, individually.I looked into type assertion, reflection etc. but not sure what is needed here.
Thanks for the help.
The text was updated successfully, but these errors were encountered: