Signin requests a session token
(ctx context.DnoteCtx, email, password string)
| 567 | |
| 568 | // Signin requests a session token |
| 569 | func Signin(ctx context.DnoteCtx, email, password string) (SigninResponse, error) { |
| 570 | payload := SigninPayload{ |
| 571 | Email: email, |
| 572 | Passowrd: password, |
| 573 | } |
| 574 | b, err := json.Marshal(payload) |
| 575 | if err != nil { |
| 576 | return SigninResponse{}, errors.Wrap(err, "marshaling payload") |
| 577 | } |
| 578 | res, err := doReq(ctx, "POST", "/v3/signin", string(b), nil) |
| 579 | if err != nil { |
| 580 | // Check if this is a 401 Unauthorized error |
| 581 | var httpErr *HTTPError |
| 582 | if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusUnauthorized { |
| 583 | return SigninResponse{}, ErrInvalidLogin |
| 584 | } |
| 585 | return SigninResponse{}, errors.Wrap(err, "making http request") |
| 586 | } |
| 587 | |
| 588 | var resp SigninResponse |
| 589 | if err := json.NewDecoder(res.Body).Decode(&resp); err != nil { |
| 590 | return SigninResponse{}, errors.Wrap(err, "decoding payload") |
| 591 | } |
| 592 | |
| 593 | return resp, nil |
| 594 | } |
| 595 | |
| 596 | // Signout deletes a user session on the server side |
| 597 | func Signout(ctx context.DnoteCtx, sessionKey string) error { |