feat(auth): add session login, logout and bearer middleware

This commit is contained in:
kk10
2026-10-05 11:54:36 +03:00
parent b94e7813ee
commit a8525778a3
10 changed files with 268 additions and 37 deletions
+8 -4
View File
@@ -48,14 +48,18 @@ func (q *Queries) DeleteExpiredSessions(ctx context.Context) (int64, error) {
return result.RowsAffected(), nil
}
const deleteSession = `-- name: DeleteSession :exec
const deleteSession = `-- name: DeleteSession :execrows
DELETE FROM sessions
WHERE token_hash = $1
AND expires_at > now()
`
func (q *Queries) DeleteSession(ctx context.Context, tokenHash string) error {
_, err := q.db.Exec(ctx, deleteSession, tokenHash)
return err
func (q *Queries) DeleteSession(ctx context.Context, tokenHash string) (int64, error) {
result, err := q.db.Exec(ctx, deleteSession, tokenHash)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getSessionUserID = `-- name: GetSessionUserID :one