diff --git a/internal/handlers/registration.go b/internal/handlers/registration.go index 5f6530a7..0d2c94e1 100644 --- a/internal/handlers/registration.go +++ b/internal/handlers/registration.go @@ -68,12 +68,18 @@ func (h *RegistrationHandlers) Register(c echo.Context) error { if !req.Expiry.IsZero() && req.Expiry.Before(time.Now()) { m.ExpiresAt = req.Expiry - if err := h.repository.SaveMachine(ctx, m); err != nil { - return err + if m.Ephemeral { + if _, err := h.repository.DeleteMachine(ctx, m.ID); err != nil { + return err + } + h.pubsub.Publish(m.TailnetID, &broker.Signal{PeersRemoved: []uint64{m.ID}}) + } else { + if err := h.repository.SaveMachine(ctx, m); err != nil { + return err + } + h.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID}) } - h.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID}) - response := tailcfg.RegisterResponse{NodeKeyExpired: true} return binder.WriteResponse(c, http.StatusOK, response) }