| Class: | Api.Auth.Utils.CurrentUserId |
|---|---|
| Assembly: | Api |
| File(s): | /home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Auth/Utils/UserIdService.cs |
| Covered lines: | 0 |
|---|---|
| Uncovered lines: | 7 |
| Coverable lines: | 7 |
| Total lines: | 24 |
| Line coverage: | 0% |
| Covered branches: | 0 |
|---|---|
| Total branches: | 6 |
| Branch coverage: | 0% |
Feature is only available for sponsors
Upgrade to PRO version| Method | Branch coverage | Crap Score | Cyclomatic complexity | Line coverage |
|---|---|---|---|---|
| .ctor(...) | 0% | 42 | 6 | 0% |
| # | Line | Line coverage | ||
|---|---|---|---|---|
1 | // SPDX-FileCopyrightText: 2026 Alper Çelik <[email protected]> | |||
2 | // | |||
3 | // SPDX-License-Identifier: AGPL-3.0-or-later | |||
4 | | |||
5 | using System.Security.Claims; | |||
6 | | |||
7 | namespace Api.Auth.Utils; | |||
8 | | |||
9 | public interface ICurrentUserId | |||
10 | { | |||
11 | public Guid? Id { get; } | |||
12 | } | |||
13 | | |||
14 | public class CurrentUserId : ICurrentUserId | |||
15 | { | |||
16 | public Guid? Id { get; init; } | |||
| 0 | 17 | public CurrentUserId(IHttpContextAccessor ctx) | ||
| 0 | 18 | { | ||
| 0 | 19 | if (ctx.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier) is { } userIdStr && Guid.TryParse(userIdStr, | ||
| 0 | 20 | { | ||
| 0 | 21 | Id = userId; | ||
| 0 | 22 | } | ||
| 0 | 23 | } | ||
24 | } |