Refactor repository methods to async and update credential logic

This commit is contained in:
Aaron Po
2026-01-22 11:14:23 -05:00
parent fd544dbd34
commit 82db763951
11 changed files with 84 additions and 67 deletions

View File

@@ -1,6 +1,6 @@
CREATE OR ALTER PROCEDURE dbo.USP_AddUserCredential(
@UserAccountId uniqueidentifier,
@Hash nvarchar(max)
CREATE OR ALTER PROCEDURE dbo.USP_AddUpdateUserCredential(
@UserAccountId UNIQUEIDENTIFIER,
@Hash NVARCHAR(MAX)
)
AS
BEGIN
@@ -16,14 +16,14 @@ BEGIN
)
THROW 50001, 'UserAccountID does not exist.', 1;
IF EXISTS (
SELECT 1
FROM dbo.UserCredential
WHERE UserAccountID = @UserAccountId
)
THROW 50002, 'UserCredential for this UserAccountID already exists.', 1;
-- invalidate old credentials
UPDATE dbo.UserCredential
SET IsRevoked = 1,
RevokedAt = GETDATE()
WHERE UserAccountId = @UserAccountId
AND IsRevoked = 0;
INSERT INTO dbo.UserCredential
(UserAccountId, Hash)
VALUES

View File

@@ -0,0 +1,18 @@
CREATE OR ALTER PROCEDURE dbo.USP_GetUserCredentialByUserAccountId(
@UserAccountId UNIQUEIDENTIFIER
)
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
SELECT
UserCredentialId,
UserAccountId,
Hash,
IsRevoked,
CreatedAt,
RevokedAt
FROM dbo.UserCredential
WHERE UserAccountId = @UserAccountId AND IsRevoked = 0;
END;