package users import ( "context" "encoding/json" "git.aiterp.net/rpdata/logbot3/internal/api" "git.aiterp.net/rpdata/logbot3/internal/models" ) type checkTokenResult struct { Token struct { User models.User `json:"user"` } `json:"token"` } var checkTokenGQL = ` query CheckTokenQuery { token { user { id permissions } } } ` // CheckToken checks the own token and returns the user information. func CheckToken(ctx context.Context) (models.User, error) { data, err := api.Global().Query(ctx, checkTokenGQL, nil, []string{"member"}) if err != nil { return models.User{}, err } result := checkTokenResult{} err = json.Unmarshal(data, &result) if err != nil { return models.User{}, err } return result.Token.User, nil }