refactor: moved hashing logic into application layer for security;

fix: error handling in auth service for database;
refactor: removed redundant taken email check;
chore: removed todos that were completed/not needed;
fix: leaking transactions in complete registration and login on error;
refactor: got rid of txless requests during transactions;
This commit is contained in:
2025-07-06 13:01:00 +03:00
parent 5e32c3cbd3
commit 333817c9e1
9 changed files with 177 additions and 121 deletions

View File

@@ -39,7 +39,7 @@ SELECT users.* FROM users
JOIN login_informations linfo ON linfo.user_id = users.id
WHERE linfo.email = @email::text;
;-- name: GetUserByLoginCredentials :one
;-- name: GetValidUserByLoginCredentials :one
SELECT
users.id,
users.username,
@@ -88,7 +88,7 @@ WHERE users.username = $1;
;-- name: CreateLoginInformation :one
INSERT INTO login_informations(user_id, email, password_hash)
VALUES ( $1, $2, crypt(@password::text, gen_salt('bf')) ) RETURNING *;
VALUES ( $1, $2, @password_hash::text ) RETURNING *;
;-- name: UpdateLoginInformationByUsername :exec
UPDATE login_informations
@@ -118,9 +118,9 @@ WHERE users.username = $1;
;-- name: CreateConfirmationCode :one
INSERT INTO confirmation_codes(user_id, code_type, code_hash)
VALUES ($1, $2, crypt(@code::text, gen_salt('bf'))) RETURNING *;
VALUES ($1, $2, @code_hash) RETURNING *;
;-- name: GetConfirmationCodeByCode :one
;-- name: GetValidConfirmationCodeByCode :one
SELECT * FROM confirmation_codes
WHERE
user_id = $1 AND