< Summary

Information
Class: Api.Auth.Utils.CurrentUserId
Assembly: Api
File(s): /home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Auth/Utils/UserIdService.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 29
Line coverage: 100%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)66.67%66100%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Auth/Utils/UserIdService.cs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <alper@alper-celik.dev>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5using System.Security.Claims;
 6
 7namespace Api.Auth.Utils;
 8
 9public interface ICurrentUserId
 10{
 11    public Guid? Id { get; }
 12}
 13
 14public class CurrentUserId : ICurrentUserId
 15{
 16    public Guid? Id { get; init; }
 17
 118    public CurrentUserId(IHttpContextAccessor ctx)
 119    {
 120        if (
 121            ctx.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier)
 122                is { } userIdStr
 123            && Guid.TryParse(userIdStr, out Guid userId)
 124        )
 125        {
 126            Id = userId;
 127        }
 128    }
 29}