Skip to content

Commit

Permalink
Current user req now needs token
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Dec 29, 2019
1 parent dac8aee commit 26c110b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Parameters struct {
apiSessionCookie *http.Cookie // is the current session cookie for the api key
environment APIEnvironment // is the current api environment to use
UserAgent string // (optional for changing user agents)
UserSessionCookie *http.Cookie // is the current session cookie for a user (on behalf)
userSessionCookie *http.Cookie // is the current session cookie for a user (on behalf)
}

// ClientDefaultOptions will return an Options struct with the default settings
Expand Down Expand Up @@ -222,7 +222,7 @@ func (c *Client) request(endpoint string, method string, payload interface{}, cu
cookie = nil
}
if len(customSessionToken) > 0 {
c.Parameters.UserSessionCookie = cookie
c.Parameters.userSessionCookie = cookie
} else {
c.Parameters.apiSessionCookie = cookie
}
Expand Down
2 changes: 1 addition & 1 deletion examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func main() {
//
// Example: Current user details
//
user, err = TonicPowAPI.CurrentUser()
user, err = TonicPowAPI.CurrentUser(userSessionToken)
if err != nil {
log.Fatalf("current user failed - api error: %s data: %s", TonicPowAPI.LastRequest.Error.Message, TonicPowAPI.LastRequest.Error.Data)
} else {
Expand Down
10 changes: 5 additions & 5 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ func (c *Client) GetUserBalance(userID uint64) (user *User, err error) {
// Required: LoginUser()
//
// For more information: https://docs.tonicpow.com/#7f6e9b5d-8c7f-4afc-8e07-7aafdd891521
func (c *Client) CurrentUser() (user *User, err error) {
func (c *Client) CurrentUser(userSessionToken string) (user *User, err error) {

// No current user
if c.Parameters.UserSessionCookie == nil {
err = fmt.Errorf("missing user session, use LoginUser() first")
if len(userSessionToken) == 0 {
err = fmt.Errorf("missing user session token")
return
}

// Fire the request
var response string
if response, err = c.request(fmt.Sprintf("%s/account", modelUser), http.MethodGet, nil, c.Parameters.UserSessionCookie.Value); err != nil {
if response, err = c.request(fmt.Sprintf("%s/account", modelUser), http.MethodGet, nil, userSessionToken); err != nil {
return
}

Expand Down Expand Up @@ -192,7 +192,7 @@ func (c *Client) LoginUser(user *User) (userSessionToken string, err error) {
}

// Convert model response
userSessionToken = c.Parameters.UserSessionCookie.Value
userSessionToken = c.Parameters.userSessionCookie.Value
return
}

Expand Down

0 comments on commit 26c110b

Please sign in to comment.