Skip to content

Commit

Permalink
client: unlink device when logging out
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 19, 2025
1 parent dceab3c commit 3db54fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (s *SignalClient) LogoutRemote(ctx context.Context) {
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to stop receive loops for logout")
}
err = s.Client.Unlink(ctx)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to unlink device")
}
err = s.Main.Store.DeleteDevice(context.TODO(), &s.Client.Store.DeviceData)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to delete device from store")
Expand Down
14 changes: 14 additions & 0 deletions pkg/signalmeow/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,20 @@ func (cli *Client) RegisterCapabilities(ctx context.Context) error {
return nil
}

func (cli *Client) Unlink(ctx context.Context) error {
username, password := cli.Store.BasicAuthCreds()
resp, err := web.SendHTTPRequest(ctx, http.MethodDelete, fmt.Sprintf("/v1/devices/%d", cli.Store.DeviceID), &web.HTTPReqOpt{
Username: &username,
Password: &password,
})
if err != nil {
return err
} else if resp.StatusCode >= 400 {
return fmt.Errorf("unexpected status code %d", resp.StatusCode)
}
return nil
}

func confirmDevice(
ctx context.Context,
username string,
Expand Down

0 comments on commit 3db54fd

Please sign in to comment.