MCPcopy Index your code
hub / github.com/dnote/dnote / Signin

Function Signin

pkg/cli/client/client.go:569–594  ·  view source on GitHub ↗

Signin requests a session token

(ctx context.DnoteCtx, email, password string)

Source from the content-addressed store, hash-verified

567
568// Signin requests a session token
569func 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
597func Signout(ctx context.DnoteCtx, sessionKey string) error {

Callers 2

DoFunction · 0.92
TestSignInFunction · 0.85

Calls 1

doReqFunction · 0.85

Tested by 1

TestSignInFunction · 0.68