2024-10-25 23:31:57 +02:00
|
|
|
-- name: CreateRefreshToken :one
|
|
|
|
INSERT INTO refresh_tokens (token, created_at, updated_at, user_id, expires_at, revoked_at)
|
|
|
|
VALUES (
|
|
|
|
$1,
|
|
|
|
NOW(),
|
|
|
|
NOW(),
|
|
|
|
$2,
|
|
|
|
$3,
|
|
|
|
NULL
|
|
|
|
)
|
2024-10-26 21:19:11 +02:00
|
|
|
RETURNING *;
|
|
|
|
|
|
|
|
-- name: RevokeRefreshToken :exec
|
|
|
|
UPDATE refresh_tokens
|
|
|
|
SET
|
|
|
|
revoked_at = NOW(),
|
|
|
|
updated_at = NOW()
|
|
|
|
WHERE token = $1;
|
|
|
|
|
|
|
|
-- name: GetUserFromRefreshToken :one
|
|
|
|
SELECT user_id FROM refresh_tokens
|
|
|
|
WHERE refresh_tokens.token = $1
|
|
|
|
AND refresh_tokens.expires_at > NOW()
|
|
|
|
AND refresh_tokens.revoked_at IS NULL;
|