flipped-aurora/gin-vue-admin · error

用户不存在

Error message

用户不存在

What it means

FindUserByUuid looks up a SysUser by its uuid column; when First(&u) returns an error (typically gorm.ErrRecordNotFound), it discards the cause and returns errors.New("用户不存在") along with an empty user. It converts any DB-level failure into the domain message 'user does not exist'.

Source

Thrown at server/service/system/sys_user.go:403

//@param: id int
//@return: err error, user *model.SysUser

func (userService *UserService) FindUserById(ctx context.Context, id int) (user *system.SysUser, err error) {
	var u system.SysUser
	err = global.GVA_DB.WithContext(ctx).Where("id = ?", id).First(&u).Error
	return &u, err
}

//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: FindUserByUuid
//@description: 通过uuid获取用户信息
//@param: uuid string
//@return: err error, user *model.SysUser

func (userService *UserService) FindUserByUuid(ctx context.Context, uuid string) (user *system.SysUser, err error) {
	var u system.SysUser
	if err = global.GVA_DB.WithContext(ctx).Where("uuid = ?", uuid).First(&u).Error; err != nil {
		return &u, errors.New("用户不存在")
	}
	return &u, nil
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: ResetPassword
//@description: 修改用户密码
//@param: ID uint
//@return: err error

func (userService *UserService) ResetPassword(ctx context.Context, ID uint, password string) (err error) {
	now := time.Now()
	err = global.GVA_DB.WithContext(ctx).Model(&system.SysUser{}).Where("id = ?", ID).Updates(map[string]interface{}{
		"password":            utils.BcryptHash(password),
		"password_updated_at": now,
	}).Error
	return err
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Re-login to obtain a fresh token with a valid uuid if the user was deleted/recreated.
  2. Verify the uuid string passed matches the sys_user.uuid column value exactly.
  3. Check the DB for the uuid: SELECT * FROM sys_user WHERE uuid = ? to confirm existence.
  4. If this follows a DB restore/reset, re-issue tokens for all users.

Example fix

// before
user, err := userService.FindUserByUuid(ctx, oldTokenUuid) // user recreated, uuid changed
// after
claims := utils.GetClaims(c) // read uuid from current valid token
user, err := userService.FindUserByUuid(ctx, claims.UUID)
Defensive patterns

Strategy: try-catch

Validate before calling

if (!uuid || uuid.length < 16) { throw new Error('无效的用户标识') }

Try / catch

user, err := userService.FindUserByUuid(ctx, uuid)
if err != nil {
  // treat as unauthenticated; force re-login
  response.FailWithMessage("登录状态失效,请重新登录", c)
  return
}

Prevention

When it happens

Trigger: Calling FindUserByUuid (sys_user.go:403) with a uuid that has no row in sys_user — expired/garbage token uuids, users deleted after a token was issued, or a malformed uuid string.

Common situations: JWT contains a uuid for a user deleted or re-created (new uuid) since issuance; stale cached user records in the front end; tokens issued before a database reset.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/d59021c4c246d275. Report an issue: GitHub.