Skip to content

Commit 7abc255

Browse files
author
Vadim Belov
committed
Fix possible null exception in login by using GetValueOrDefault
Replaced userId.Value with userId.GetValueOrDefault() in OnUserLoggingInAsync call to prevent potential exceptions when userId is null. This change improves code safety without altering existing logic.
1 parent 5411ce9 commit 7abc255

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Sources/EasyExtensions.AspNetCore.Authorization/Controllers/BaseAuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public async Task<IActionResult> Login([FromBody] LoginRequestDto request)
153153
Guid? userId = await FindUserByUsernameAsync(request.Username);
154154
if (!userId.HasValue || userId == Guid.Empty)
155155
{
156-
await OnUserLoggingInAsync(userId.Value, AuthType.Credentials, AuthRejectionType.UserNotFound);
156+
await OnUserLoggingInAsync(userId.GetValueOrDefault(), AuthType.Credentials, AuthRejectionType.UserNotFound);
157157
return this.ApiUnauthorized("Invalid username or password");
158158
}
159159
bool canLogin = await CanUserLoginAsync(userId.Value);

0 commit comments

Comments
 (0)