mirror of
https://github.com/jsiebens/ionscale.git
synced 2026-03-31 15:07:49 +01:00
fix: log in with different use should create new machine entry
This commit is contained in:
@@ -389,9 +389,9 @@ func (r *repository) GetNextMachineNameIndex(ctx context.Context, tailnetID uint
|
||||
return m.NameIdx + 1, nil
|
||||
}
|
||||
|
||||
func (r *repository) GetMachineByKey(ctx context.Context, tailnetID uint64, machineKey string) (*Machine, error) {
|
||||
func (r *repository) GetMachineByKeyAndUser(ctx context.Context, machineKey string, userID uint64) (*Machine, error) {
|
||||
var m Machine
|
||||
tx := r.withContext(ctx).Preload("Tailnet").Preload("User").Take(&m, "tailnet_id = ? AND machine_key = ?", tailnetID, machineKey)
|
||||
tx := r.withContext(ctx).Preload("Tailnet").Preload("User").Take(&m, "machine_key = ? AND user_id = ?", machineKey, userID)
|
||||
|
||||
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
|
||||
@@ -58,7 +58,7 @@ type Repository interface {
|
||||
SaveMachine(ctx context.Context, m *Machine) error
|
||||
DeleteMachine(ctx context.Context, id uint64) (bool, error)
|
||||
GetMachine(ctx context.Context, id uint64) (*Machine, error)
|
||||
GetMachineByKey(ctx context.Context, tailnetID uint64, key string) (*Machine, error)
|
||||
GetMachineByKeyAndUser(ctx context.Context, key string, userID uint64) (*Machine, error)
|
||||
GetMachineByKeys(ctx context.Context, machineKey string, nodeKey string) (*Machine, error)
|
||||
CountMachinesWithIPv4(ctx context.Context, ip string) (int64, error)
|
||||
GetNextMachineNameIndex(ctx context.Context, tailnetID uint64, name string) (uint64, error)
|
||||
|
||||
@@ -446,7 +446,7 @@ func (h *AuthenticationHandlers) endMachineRegistrationFlow(c echo.Context, form
|
||||
|
||||
var m *domain.Machine
|
||||
|
||||
m, err := h.repository.GetMachineByKey(ctx, tailnet.ID, machineKey)
|
||||
m, err := h.repository.GetMachineByKeyAndUser(ctx, machineKey, user.ID)
|
||||
if err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func (h *RegistrationHandlers) authenticateMachineWithAuthKey(c echo.Context, ma
|
||||
|
||||
var m *domain.Machine
|
||||
|
||||
m, err = h.repository.GetMachineByKey(ctx, tailnet.ID, machineKey)
|
||||
m, err = h.repository.GetMachineByKeyAndUser(ctx, machineKey, user.ID)
|
||||
if err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user