feat(auth): persist preferred language per user and session
Refs #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
7dd1f87ffe
commit
dde7b890b8
7 files changed
+60
-15
No files matched your search
@@ -23,18 +23,24 @@ func (q *Queries) AnyUserExists(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (email, display_name, password_hash) VALUES ($1, $2, $3)
|
||||
RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at
|
||||
INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
Email string
|
||||
DisplayName string
|
||||
PasswordHash *string
|
||||
Locale *string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
||||
row := q.db.QueryRow(ctx, createUser, arg.Email, arg.DisplayName, arg.PasswordHash)
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.Email,
|
||||
arg.DisplayName,
|
||||
arg.PasswordHash,
|
||||
arg.Locale,
|
||||
)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
@@ -46,6 +52,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e
|
||||
&i.UpdatedAt,
|
||||
&i.TotpSecret,
|
||||
&i.TotpEnabledAt,
|
||||
&i.Locale,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -86,7 +93,7 @@ func (q *Queries) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error {
|
||||
}
|
||||
|
||||
const getUser = `-- name: GetUser :one
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at FROM users WHERE id = $1
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale FROM users WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
@@ -102,12 +109,13 @@ func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
&i.UpdatedAt,
|
||||
&i.TotpSecret,
|
||||
&i.TotpEnabledAt,
|
||||
&i.Locale,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at FROM users WHERE email = $1
|
||||
SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale FROM users WHERE email = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
||||
@@ -123,6 +131,7 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error
|
||||
&i.UpdatedAt,
|
||||
&i.TotpSecret,
|
||||
&i.TotpEnabledAt,
|
||||
&i.Locale,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -140,3 +149,17 @@ func (q *Queries) SetPasswordHash(ctx context.Context, arg SetPasswordHashParams
|
||||
_, err := q.db.Exec(ctx, setPasswordHash, arg.ID, arg.PasswordHash)
|
||||
return err
|
||||
}
|
||||
|
||||
const setUserLocale = `-- name: SetUserLocale :exec
|
||||
UPDATE users SET locale = $2, updated_at = now() WHERE id = $1
|
||||
`
|
||||
|
||||
type SetUserLocaleParams struct {
|
||||
ID uuid.UUID
|
||||
Locale *string
|
||||
}
|
||||
|
||||
func (q *Queries) SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error {
|
||||
_, err := q.db.Exec(ctx, setUserLocale, arg.ID, arg.Locale)
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user