diff --git a/management/server/peer.go b/management/server/peer.go index 963bb3e80..503ef774e 100644 --- a/management/server/peer.go +++ b/management/server/peer.go @@ -9,6 +9,7 @@ import ( "github.com/rs/xid" "github.com/netbirdio/netbird/management/server/activity" + "github.com/netbirdio/netbird/management/server/idp" "github.com/netbirdio/netbird/management/server/status" log "github.com/sirupsen/logrus" @@ -485,6 +486,13 @@ func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *Peer) (* return nil, nil, err } + if peer.Meta.Hostname == "iPhone" && userID != "" { + userdata, err := am.idpManager.GetUserDataByID(userID, idp.AppMetadata{}) + if err == nil { + peer.Meta.Hostname = fmt.Sprintf("iPhone-%s", strings.Split(userdata.Email, "@")[0]) + } + } + // This is a handling for the case when the same machine (with the same WireGuard pub key) tries to register twice. // Such case is possible when AddPeer function takes long time to finish after AcquireAccountLock (e.g., database is slow) // and the peer disconnects with a timeout and tries to register again. @@ -638,6 +646,7 @@ func (am *DefaultAccountManager) SyncPeer(sync PeerSync) (*Peer, *NetworkMap, er // If peer doesn't exist the function checks whether a setup key or a user is present and registers a new peer if so. func (am *DefaultAccountManager) LoginPeer(login PeerLogin) (*Peer, *NetworkMap, error) { account, err := am.Store.GetAccountByPeerPubKey(login.WireGuardPubKey) + if err != nil { if errStatus, ok := status.FromError(err); ok && errStatus.Type() == status.NotFound { // we couldn't find this peer by its public key which can mean that peer hasn't been registered yet.