fix(node): clear consumed invitations after confirmed pairing
This commit is contained in:
@@ -81,6 +81,13 @@ func OpenPairing(store *Store, dir, version string, inventory func() Inventory)
|
||||
if (p.state.Phase == "inviting" || p.state.Phase == "pending") && p.state.Invitation == nil {
|
||||
return nil, errors.New("incomplete invitation")
|
||||
}
|
||||
if (p.state.Phase == "paired" || p.state.Phase == "revoked") && p.state.Invitation != nil {
|
||||
next := p.state
|
||||
next.Invitation = nil
|
||||
if e := p.save(next); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
func savePrivateJSON(path string, value any) error {
|
||||
@@ -186,6 +193,8 @@ func (p *Pairing) invite(address string) (map[string]any, error) {
|
||||
if e := p.save(PairState{Schema: PairSchema, Phase: "inviting", Invitation: i, Revocations: p.state.Revocations}); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
p.connection = "offline"
|
||||
p.lastSeen = 0
|
||||
id, _ := p.store.Public()
|
||||
code, _ := json.Marshal(map[string]any{"schema": PairSchema, "node_id": id, "id": i.ID, "endpoint": i.Endpoint, "expires_at": i.ExpiresAt, "secret": secret})
|
||||
return map[string]any{"code": "MCN1." + base64.RawURLEncoding.EncodeToString(code), "expires_at": i.ExpiresAt}, nil
|
||||
|
||||
Reference in New Issue
Block a user