Skip to content

Commit

Permalink
login before checking status
Browse files Browse the repository at this point in the history
the status enpoint requires auth, at least in my Cloud Key Firmware 2.X
(UniFi OS) setup.
Presumably there are benefits to checking status before logging in; in
which case I expect this PR will need to be edited.
  • Loading branch information
Patricol authored and paultyng committed Jan 31, 2021
1 parent b5c55d8 commit c55b431
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions unifi/unifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
} `json:"meta"`
}

err = c.do(ctx, "GET", c.statusPath, nil, &status)
if err != nil {
return err
}
c.version = status.Meta.ServerVersion

err = c.do(ctx, "POST", c.loginPath, &struct {
Username string `json:"username"`
Password string `json:"password"`
Expand All @@ -164,6 +158,12 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
return err
}

err = c.do(ctx, "GET", c.statusPath, nil, &status)
if err != nil {
return err
}
c.version = status.Meta.ServerVersion

return nil
}

Expand Down

0 comments on commit c55b431

Please sign in to comment.