mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 08:06:37 +08:00
fix(user): assign snowflake IDs on registration
The HTTP register path left ID at 0, so SQLite/GORM filled a serial primary key. CreateUser now generates a snowflake ID when none is set, matching admin create and OAuth signup.
This commit is contained in:
@@ -6,6 +6,7 @@ package user
|
||||
import (
|
||||
"Wavelet/core"
|
||||
"Wavelet/core/contracts"
|
||||
"Wavelet/pkg/idgen"
|
||||
"Wavelet/pkg/util"
|
||||
"context"
|
||||
"errors"
|
||||
@@ -82,8 +83,11 @@ func GetUserByEmail(ctx context.Context, email string) (*User, error) {
|
||||
return &u, nil
|
||||
}
|
||||
|
||||
// CreateUser 创建用户
|
||||
// CreateUser 创建用户。ID 为空时用雪花算法分配,避免 SQLite/GORM 把 0 当成自增主键。
|
||||
func CreateUser(ctx context.Context, u *User) error {
|
||||
if u != nil && u.ID == 0 {
|
||||
u.ID = idgen.NextUint64ID()
|
||||
}
|
||||
return getDB(ctx).Create(u).Error
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user