@@ -40,9 +40,33 @@ func (bl *FxBlockchain) handleAutoPinPair(from peer.ID, w http.ResponseWriter, r
4040 props = make (map [string ]interface {})
4141 }
4242
43- // Reject if already paired
44- if existingToken , ok := props ["auto_pin_token" ]; ok && existingToken != nil && existingToken != "" {
45- http .Error (w , `{"message":"already paired, unpair first"}` , http .StatusConflict )
43+ // If already paired, return the existing credentials so the app can
44+ // re-acquire them (e.g. after clearing storage). Update the token/endpoint
45+ // in case they changed.
46+ if existingSecret , ok := props ["auto_pin_pairing_secret" ]; ok && existingSecret != nil && existingSecret != "" {
47+ // Update token and endpoint in case the cloud rotated them
48+ props ["auto_pin_token" ] = req .PinningToken
49+ props ["auto_pin_endpoint" ] = req .PinningEndpoint
50+ if err := config .WriteProperties (props ); err != nil {
51+ log .Errorw ("failed to update properties" , "err" , err )
52+ http .Error (w , `{"message":"failed to update pairing config"}` , http .StatusInternalServerError )
53+ return
54+ }
55+
56+ hardwareID , err := wifi .GetHardwareID ()
57+ if err != nil {
58+ log .Warnw ("failed to get hardware ID" , "err" , err )
59+ hardwareID = ""
60+ }
61+
62+ resp := AutoPinPairResponse {
63+ Status : "already_paired" ,
64+ PairingSecret : existingSecret .(string ),
65+ HardwareID : hardwareID ,
66+ }
67+ w .Header ().Set ("Content-Type" , "application/json" )
68+ w .WriteHeader (http .StatusOK )
69+ json .NewEncoder (w ).Encode (resp )
4670 return
4771 }
4872
0 commit comments