# ServerIdentityService

- File ID: file:10axm6l:serveridentityservice-cs
- Path: NexusReader.Web/Services/ServerIdentityService.cs
- Role: service
- Layer: application

## Purpose

Provides server-side identity operations for the web app: validating credentials, registering users, reading the authenticated profile, and small no-op token/logout helpers tailored for Blazor Server constraints.

## Key Details

This service intentionally validates credentials but avoids performing server-side cookie sign-in due to Blazor/SignalR header/cookie lifecycle constraints; it returns friendly Result objects and delegates profile retrieval to a mediator query handler.

## Symbols

- ServerIdentityService: Provides server-side identity operations for the web app: validating credentials, registering users, reading the authenticated profile, and small no-op token/logout helpers tailored for Blazor Server constraints.
- ServerIdentityService(): Constructor - wires up UserManager, SignInManager, HttpContextAccessor, Mediator and native storage dependency fields.
- LoginAsync(): Validates user credentials server-side (for Blazor Server) but deliberately does not perform cookie sign-in; returns success/failure result.
- LogoutAsync(): No-op logout helper for Blazor/SignalR scenarios; instructs UI to use a logout-form endpoint to clear cookies.
- RegisterAsync(): Creates a new NexusUser with default subscription/tenant and returns success or the first identity error; does not sign in the user.
- RefreshTokenAsync(): Placeholder/no-op refresh token implementation returning success.
- GetProfileAsync(): Reads the current authenticated user's ID from HttpContext and fetches their profile via a mediator query; returns profile or failure.

## Dependencies

- No resolved dependencies.

## Calls

- No resolved calls.

## Unresolved References

- dependency-target: NexusReader.Application.Queries.User
- dependency-target: NexusReader.Application.DTOs.User
- dependency-target: Microsoft.AspNetCore.Identity (framework)
- call-target: NexusReader.Application.Queries.User
- interaction-target: var user = await _userManager.FindByEmailAsync(email);
- interaction-target: return Result.Fail(result.Errors.Select(e => e.Description).FirstOrDefault() ?? "Rejestracja nie powiodła się.");
- interaction-target: var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
- interaction-target: _userManager.FindByEmailAsync(email) -- framework identity external call
- interaction-target: _userManager.IsLockedOutAsync(user) -- framework identity external call
- interaction-target: _userManager.CheckPasswordAsync(user, password) -- framework identity external call
- interaction-target: await _userManager.ResetAccessFailedCountAsync(user)
- interaction-target: _userManager.CreateAsync(user, password) -- framework identity external call
- interaction-target: _mediator.Send(new GetUserProfileQuery(userId)) -> delegates to application layer handler

## Coverage

- Symbols: 7
- Executable symbols: 6
- Executable symbols with control flow: 6
- Grounded edges: 7
- Unresolved references: 13
- Control-flow fragments: 6
- Unresolved jumps: 1
- Unsupported constructs: 0
- Control-flow coverage: 100%
- Required diagrams: 2
- Generated diagrams: 5

## Control Flow Fragments

- ServerIdentityService: 3 nodes, 2 edges, 0 jumps, 0 unsupported constructs
- LoginAsync: 42 nodes, 47 edges, 0 jumps, 0 unsupported constructs
- LogoutAsync: 4 nodes, 3 edges, 0 jumps, 0 unsupported constructs
- RegisterAsync: 20 nodes, 21 edges, 0 jumps, 0 unsupported constructs
- RefreshTokenAsync: 2 nodes, 1 edges, 0 jumps, 0 unsupported constructs
- GetProfileAsync: 31 nodes, 36 edges, 1 jumps, 0 unsupported constructs

## Diagrams

### ServerIdentityService Neighborhood

```mermaid
flowchart LR
    class_1l2fmrv_serveridentityservice("ServerIdentityService")
    file_10axm6l_serveridentityservice_cs("ServerIdentityService")
    method_13af2s9_getprofileasync[["GetProfileAsync()"]]
    method_1a1t07w_logoutasync[["LogoutAsync()"]]
    method_1ekb3x6_registerasync[["RegisterAsync()"]]
    method_1pi9wuc_loginasync[["LoginAsync()"]]
    method_icuddu_serveridentityservice[["ServerIdentityService()"]]
    method_pcq8ik_refreshtokenasync[["RefreshTokenAsync()"]]
```

### ServerIdentityService Execution Overview

```mermaid
flowchart TD
    class_1l2fmrv_serveridentityservice("ServerIdentityService")
    method_13af2s9_getprofileasync[["GetProfileAsync()"]]
    method_1a1t07w_logoutasync[["LogoutAsync()"]]
    method_1ekb3x6_registerasync[["RegisterAsync()"]]
    method_1pi9wuc_loginasync[["LoginAsync()"]]
    method_icuddu_serveridentityservice[["ServerIdentityService()"]]
    method_pcq8ik_refreshtokenasync[["RefreshTokenAsync()"]]
    unresolved_unresolved_14uh522_interaction_target{"Unresolved: _userManager.FindByEmailAsync(email) -- framework identity external call"}
    unresolved_unresolved_187tll3_interaction_target{"Unresolved: await _userManager.ResetAccessFailedCountAsync(user)"}
    unresolved_unresolved_1kxilh5_interaction_target{"Unresolved: _userManager.CheckPasswordAsync(user, password) -- framework identity external call"}
    unresolved_unresolved_1mz3kzy_interaction_target{"Unresolved: _mediator.Send(new GetUserProfileQuery(userId)) -> delegates to application layer handler"}
    unresolved_unresolved_1oipl4j_interaction_target{"Unresolved: return Result.Fail(result.Errors.Select(e => e.Description).FirstOrDefault() ?? \\"Rejestracja nie powiodła się.\\");"}
    unresolved_unresolved_5i4yvb_interaction_target{"Unresolved: var user = await _userManager.FindByEmailAsync(email);"}
    unresolved_unresolved_asmgjp_interaction_target{"Unresolved: var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);"}
    unresolved_unresolved_by6qd7_interaction_target{"Unresolved: _userManager.IsLockedOutAsync(user) -- framework identity external call"}
    unresolved_unresolved_r9ylhn_call_target{"Unresolved: GetUserProfileQuery"}
    unresolved_unresolved_ys6116_interaction_target{"Unresolved: _userManager.CreateAsync(user, password) -- framework identity external call"}
    class_1l2fmrv_serveridentityservice -->|contains| method_13af2s9_getprofileasync
    class_1l2fmrv_serveridentityservice -->|contains| method_1a1t07w_logoutasync
    class_1l2fmrv_serveridentityservice -->|contains| method_1ekb3x6_registerasync
    class_1l2fmrv_serveridentityservice -->|contains| method_1pi9wuc_loginasync
    class_1l2fmrv_serveridentityservice -->|contains| method_icuddu_serveridentityservice
    class_1l2fmrv_serveridentityservice -->|contains| method_pcq8ik_refreshtokenasync
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_14uh522_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_187tll3_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_1kxilh5_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_1mz3kzy_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_1oipl4j_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_5i4yvb_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_asmgjp_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_by6qd7_interaction_target
    class_1l2fmrv_serveridentityservice -->|unresolved interaction| unresolved_unresolved_ys6116_interaction_target
    method_13af2s9_getprofileasync -->|unresolved call| unresolved_unresolved_r9ylhn_call_target
```

### LoginAsync() Control Flow

_Warnings: diagram method_1pi9wuc_loginasync__fragment_diagram exceeds preferred complexity thresholds (42 nodes, 47 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart TD
    method_1pi9wuc_loginasync__action_41_loginasync_try_41_0__try("Begins protected execution")
    method_1pi9wuc_loginasync__action_41_try_catch_41__linear("Wraps credential verification to return friendly failure on exceptions")
    method_1pi9wuc_loginasync__action_43_loginasync_await_43_2__await[["Waits for async work"]]
    method_1pi9wuc_loginasync__action_44_guard_clause_44__condition{"user == null"}
    method_1pi9wuc_loginasync__action_44_guard_clause_44__false("return fail")
    method_1pi9wuc_loginasync__action_44_guard_clause_44__merge("merge")
    method_1pi9wuc_loginasync__action_44_guard_clause_44__true("invalid")
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__condition{"user == null) return Result.Fail(\\"Nieprawidłowy e-mail lub hasło.\\""}
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__false("continue")
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__merge("merge")
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__true("exit")
    method_1pi9wuc_loginasync__action_47_guard_clause_47__condition{"IsLockedOutAsync(user) == true"}
    method_1pi9wuc_loginasync__action_47_guard_clause_47__false("return fail")
    method_1pi9wuc_loginasync__action_47_guard_clause_47__merge("merge")
    method_1pi9wuc_loginasync__action_47_guard_clause_47__true("locked")
    method_1pi9wuc_loginasync__action_47_loginasync_await_47_5__await[["Waits for async work"]]
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__condition{"await _userManager.IsLockedOutAsync(user)) return Result.Fail(\\"Konto zostało zablokowane.\\""}
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__false("continue")
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__merge("merge")
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__true("exit")
    method_1pi9wuc_loginasync__action_50_loginasync_await_50_6__await[["Waits for async work"]]
    method_1pi9wuc_loginasync__action_51_guard_clause_51__condition{"!isCorrect"}
    method_1pi9wuc_loginasync__action_51_guard_clause_51__false("return fail")
    method_1pi9wuc_loginasync__action_51_guard_clause_51__merge("merge")
    method_1pi9wuc_loginasync__action_51_guard_clause_51__true("increment-failure")
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__condition{"!isCorrect"}
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__false("false")
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__merge("merge")
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__true("true")
    method_1pi9wuc_loginasync__action_53_loginasync_await_53_8__await[["Waits for async work"]]
    method_1pi9wuc_loginasync__action_58_loginasync_await_58_10__await[["Waits for async work"]]
    method_1pi9wuc_loginasync__action_66_loginasync_catch_66_12__catch("catch Exception ex")
    method_1pi9wuc_loginasync__entry(["LoginAsync entry"])
    method_1pi9wuc_loginasync__action_43_external_call_43__linear("Find user by email")
    method_1pi9wuc_loginasync__action_43_loginasync_repository_read_43_1__linear[("Reads repository or persistence state")]
    method_1pi9wuc_loginasync__action_47_external_call_47__linear("Check if account is locked")
    method_1pi9wuc_loginasync__action_50_external_call_50__linear("Verify password")
    method_1pi9wuc_loginasync__action_58_external_call_58__linear("Reset access failed count after successful auth")
    method_1pi9wuc_loginasync__action_54_loginasync_return_54_9__return(["Returns result"])
    method_1pi9wuc_loginasync__action_64_loginasync_return_64_11__return(["Returns result"])
    method_1pi9wuc_loginasync__action_64_return_64__return(["Return OK to indicate credentials valid (no server-side cookie set here)"])
    method_1pi9wuc_loginasync__action_68_loginasync_return_68_13__return(["Returns result"])
    method_1pi9wuc_loginasync__action_41_loginasync_try_41_0__try -->|next| method_1pi9wuc_loginasync__action_43_loginasync_await_43_2__await
    method_1pi9wuc_loginasync__action_41_try_catch_41__linear -->|next| method_1pi9wuc_loginasync__action_41_loginasync_try_41_0__try
    method_1pi9wuc_loginasync__action_43_external_call_43__linear -->|next| method_1pi9wuc_loginasync__action_44_guard_clause_44__condition
    method_1pi9wuc_loginasync__action_43_loginasync_await_43_2__await -->|next| method_1pi9wuc_loginasync__action_43_loginasync_repository_read_43_1__linear
    method_1pi9wuc_loginasync__action_43_loginasync_repository_read_43_1__linear -->|next| method_1pi9wuc_loginasync__action_43_external_call_43__linear
    method_1pi9wuc_loginasync__action_44_guard_clause_44__condition -->|return fail| method_1pi9wuc_loginasync__action_44_guard_clause_44__false
    method_1pi9wuc_loginasync__action_44_guard_clause_44__condition -->|invalid| method_1pi9wuc_loginasync__action_44_guard_clause_44__true
    method_1pi9wuc_loginasync__action_44_guard_clause_44__false -->|next| method_1pi9wuc_loginasync__action_44_guard_clause_44__merge
    method_1pi9wuc_loginasync__action_44_guard_clause_44__merge -->|next| method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__condition
    method_1pi9wuc_loginasync__action_44_guard_clause_44__true -->|next| method_1pi9wuc_loginasync__action_44_guard_clause_44__merge
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__condition -->|continue| method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__false
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__condition -->|exit| method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__true
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__false -->|next| method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__merge
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__merge -->|next| method_1pi9wuc_loginasync__action_47_loginasync_await_47_5__await
    method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__true -->|next| method_1pi9wuc_loginasync__action_44_loginasync_guard_clause_44_3__merge
    method_1pi9wuc_loginasync__action_47_external_call_47__linear -->|next| method_1pi9wuc_loginasync__action_50_loginasync_await_50_6__await
    method_1pi9wuc_loginasync__action_47_guard_clause_47__condition -->|return fail| method_1pi9wuc_loginasync__action_47_guard_clause_47__false
    method_1pi9wuc_loginasync__action_47_guard_clause_47__condition -->|locked| method_1pi9wuc_loginasync__action_47_guard_clause_47__true
    method_1pi9wuc_loginasync__action_47_guard_clause_47__false -->|next| method_1pi9wuc_loginasync__action_47_guard_clause_47__merge
    method_1pi9wuc_loginasync__action_47_guard_clause_47__merge -->|next| method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__condition
    method_1pi9wuc_loginasync__action_47_guard_clause_47__true -->|next| method_1pi9wuc_loginasync__action_47_guard_clause_47__merge
    method_1pi9wuc_loginasync__action_47_loginasync_await_47_5__await -->|next| method_1pi9wuc_loginasync__action_47_guard_clause_47__condition
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__condition -->|continue| method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__false
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__condition -->|exit| method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__true
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__false -->|next| method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__merge
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__merge -->|next| method_1pi9wuc_loginasync__action_47_external_call_47__linear
    method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__true -->|next| method_1pi9wuc_loginasync__action_47_loginasync_guard_clause_47_4__merge
    method_1pi9wuc_loginasync__action_50_external_call_50__linear -->|next| method_1pi9wuc_loginasync__action_51_guard_clause_51__condition
    method_1pi9wuc_loginasync__action_50_loginasync_await_50_6__await -->|next| method_1pi9wuc_loginasync__action_50_external_call_50__linear
    method_1pi9wuc_loginasync__action_51_guard_clause_51__condition -->|return fail| method_1pi9wuc_loginasync__action_51_guard_clause_51__false
    method_1pi9wuc_loginasync__action_51_guard_clause_51__condition -->|increment-failure| method_1pi9wuc_loginasync__action_51_guard_clause_51__true
    method_1pi9wuc_loginasync__action_51_guard_clause_51__false -->|next| method_1pi9wuc_loginasync__action_51_guard_clause_51__merge
    method_1pi9wuc_loginasync__action_51_guard_clause_51__merge -->|next| method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__condition
    method_1pi9wuc_loginasync__action_51_guard_clause_51__true -->|next| method_1pi9wuc_loginasync__action_51_guard_clause_51__merge
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__condition -->|false| method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__false
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__condition -->|true| method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__true
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__false -->|next| method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__merge
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__merge -->|next| method_1pi9wuc_loginasync__action_53_loginasync_await_53_8__await
    method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__true -->|next| method_1pi9wuc_loginasync__action_51_loginasync_branch_51_7__merge
    method_1pi9wuc_loginasync__action_53_loginasync_await_53_8__await -->|return| method_1pi9wuc_loginasync__action_54_loginasync_return_54_9__return
    method_1pi9wuc_loginasync__action_54_loginasync_return_54_9__return -->|next| method_1pi9wuc_loginasync__action_58_loginasync_await_58_10__await
    method_1pi9wuc_loginasync__action_58_external_call_58__linear -->|return| method_1pi9wuc_loginasync__action_64_loginasync_return_64_11__return
    method_1pi9wuc_loginasync__action_58_loginasync_await_58_10__await -->|next| method_1pi9wuc_loginasync__action_58_external_call_58__linear
    method_1pi9wuc_loginasync__action_64_loginasync_return_64_11__return -->|return| method_1pi9wuc_loginasync__action_64_return_64__return
    method_1pi9wuc_loginasync__action_64_return_64__return -->|exception| method_1pi9wuc_loginasync__action_66_loginasync_catch_66_12__catch
    method_1pi9wuc_loginasync__action_66_loginasync_catch_66_12__catch -->|return| method_1pi9wuc_loginasync__action_68_loginasync_return_68_13__return
    method_1pi9wuc_loginasync__entry -->|next| method_1pi9wuc_loginasync__action_41_try_catch_41__linear
```

### RegisterAsync() Control Flow

_Warnings: diagram method_1ekb3x6_registerasync__fragment_diagram exceeds preferred complexity thresholds (20 nodes, 21 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart TD
    method_1ekb3x6_registerasync__action_100_registerasync_catch_100_7__catch("catch Exception ex")
    method_1ekb3x6_registerasync__action_81_registerasync_try_81_0__try("Begins protected execution")
    method_1ekb3x6_registerasync__action_81_try_catch_81__linear("Wraps registration to return friendly failure on exceptions")
    method_1ekb3x6_registerasync__action_83_object_construction_83__linear("Build new NexusUser DTO/entity for creation")
    method_1ekb3x6_registerasync__action_90_registerasync_await_90_1__await[["Waits for async work"]]
    method_1ekb3x6_registerasync__action_92_branch_92__condition{"result.Succeeded"}
    method_1ekb3x6_registerasync__action_92_branch_92__false("failed -> return first error")
    method_1ekb3x6_registerasync__action_92_branch_92__merge("merge")
    method_1ekb3x6_registerasync__action_92_branch_92__true("succeeded -> return OK")
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__condition{"result.Succeeded"}
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__false("false")
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__merge("merge")
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__true("true")
    method_1ekb3x6_registerasync__action_98_registerasync_mapping_98_5__linear("Maps data or transforms shape")
    method_1ekb3x6_registerasync__entry(["RegisterAsync entry"])
    method_1ekb3x6_registerasync__action_90_external_call_90__linear("Persist new user")
    method_1ekb3x6_registerasync__action_98_registerasync_repository_read_98_4__linear[("Reads repository or persistence state")]
    method_1ekb3x6_registerasync__action_102_registerasync_return_102_8__return(["Returns result"])
    method_1ekb3x6_registerasync__action_95_registerasync_return_95_3__return(["Returns result"])
    method_1ekb3x6_registerasync__action_98_registerasync_return_98_6__return(["Returns result"])
    method_1ekb3x6_registerasync__action_100_registerasync_catch_100_7__catch -->|return| method_1ekb3x6_registerasync__action_102_registerasync_return_102_8__return
    method_1ekb3x6_registerasync__action_81_registerasync_try_81_0__try -->|next| method_1ekb3x6_registerasync__action_83_object_construction_83__linear
    method_1ekb3x6_registerasync__action_81_try_catch_81__linear -->|next| method_1ekb3x6_registerasync__action_81_registerasync_try_81_0__try
    method_1ekb3x6_registerasync__action_83_object_construction_83__linear -->|next| method_1ekb3x6_registerasync__action_90_registerasync_await_90_1__await
    method_1ekb3x6_registerasync__action_90_external_call_90__linear -->|next| method_1ekb3x6_registerasync__action_92_branch_92__condition
    method_1ekb3x6_registerasync__action_90_registerasync_await_90_1__await -->|next| method_1ekb3x6_registerasync__action_90_external_call_90__linear
    method_1ekb3x6_registerasync__action_92_branch_92__condition -->|failed -> return first error| method_1ekb3x6_registerasync__action_92_branch_92__false
    method_1ekb3x6_registerasync__action_92_branch_92__condition -->|succeeded -> return OK| method_1ekb3x6_registerasync__action_92_branch_92__true
    method_1ekb3x6_registerasync__action_92_branch_92__false -->|next| method_1ekb3x6_registerasync__action_92_branch_92__merge
    method_1ekb3x6_registerasync__action_92_branch_92__merge -->|next| method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__condition
    method_1ekb3x6_registerasync__action_92_branch_92__true -->|next| method_1ekb3x6_registerasync__action_92_branch_92__merge
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__condition -->|false| method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__false
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__condition -->|true| method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__true
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__false -->|next| method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__merge
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__merge -->|return| method_1ekb3x6_registerasync__action_95_registerasync_return_95_3__return
    method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__true -->|next| method_1ekb3x6_registerasync__action_92_registerasync_branch_92_2__merge
    method_1ekb3x6_registerasync__action_95_registerasync_return_95_3__return -->|return| method_1ekb3x6_registerasync__action_98_registerasync_return_98_6__return
    method_1ekb3x6_registerasync__action_98_registerasync_mapping_98_5__linear -->|exception| method_1ekb3x6_registerasync__action_100_registerasync_catch_100_7__catch
    method_1ekb3x6_registerasync__action_98_registerasync_repository_read_98_4__linear -->|next| method_1ekb3x6_registerasync__action_98_registerasync_mapping_98_5__linear
    method_1ekb3x6_registerasync__action_98_registerasync_return_98_6__return -->|next| method_1ekb3x6_registerasync__action_98_registerasync_repository_read_98_4__linear
    method_1ekb3x6_registerasync__entry -->|next| method_1ekb3x6_registerasync__action_81_try_catch_81__linear
```

### GetProfileAsync() Control Flow

_Warnings: diagram method_13af2s9_getprofileasync__fragment_diagram exceeds preferred complexity thresholds (31 nodes, 36 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart TD
    method_13af2s9_getprofileasync__call_116_GetUserProfileQuery[["GetUserProfileQuery"]]
    method_13af2s9_getprofileasync__action_110_guard_clause_110__condition{"user == null OR user.Identity?.IsAuthenticated != true"}
    method_13af2s9_getprofileasync__action_110_guard_clause_110__false("continue")
    method_13af2s9_getprofileasync__action_110_guard_clause_110__merge("merge")
    method_13af2s9_getprofileasync__action_110_guard_clause_110__true("not authenticated -> return fail")
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__condition{"user == null || !user.Identity?.IsAuthenticated == true) return Result.Fail(\\"Not authenticated.\\""}
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__false("continue")
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__merge("merge")
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__true("exit")
    method_13af2s9_getprofileasync__action_113_extraction_113__linear("Extract user ID claim")
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__condition{"userId == null) return Result.Fail(\\"User ID not found.\\""}
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__false("continue")
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__merge("merge")
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__true("exit")
    method_13af2s9_getprofileasync__action_114_guard_clause_114__condition{"userId == null"}
    method_13af2s9_getprofileasync__action_114_guard_clause_114__false("continue")
    method_13af2s9_getprofileasync__action_114_guard_clause_114__merge("merge")
    method_13af2s9_getprofileasync__action_114_guard_clause_114__true("missing id -> return fail")
    method_13af2s9_getprofileasync__action_116_getprofileasync_await_116_3__await[["Waits for async work"]]
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__condition{"result.IsFailed) return Result.Fail(result.Errors"}
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__false("continue")
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__merge("merge")
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__true("exit")
    method_13af2s9_getprofileasync__action_117_guard_clause_117__condition{"result.IsFailed"}
    method_13af2s9_getprofileasync__action_117_guard_clause_117__false("successful -> return profile")
    method_13af2s9_getprofileasync__action_117_guard_clause_117__merge("merge")
    method_13af2s9_getprofileasync__action_117_guard_clause_117__true("query failed -> return fail")
    method_13af2s9_getprofileasync__entry(["GetProfileAsync entry"])
    method_13af2s9_getprofileasync__action_113_getprofileasync_repository_read_113_1__linear[("Reads repository or persistence state")]
    method_13af2s9_getprofileasync__action_116_external_call_116__linear("Query for user profile via mediator")
    method_13af2s9_getprofileasync__action_119_getprofileasync_return_119_5__return(["Returns result"])
    method_13af2s9_getprofileasync__action_110_guard_clause_110__condition -->|continue| method_13af2s9_getprofileasync__action_110_guard_clause_110__false
    method_13af2s9_getprofileasync__action_110_guard_clause_110__condition -->|not authenticated -> return fail| method_13af2s9_getprofileasync__action_110_guard_clause_110__true
    method_13af2s9_getprofileasync__action_110_guard_clause_110__false -->|next| method_13af2s9_getprofileasync__action_110_guard_clause_110__merge
    method_13af2s9_getprofileasync__action_110_guard_clause_110__merge -->|next| method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__condition
    method_13af2s9_getprofileasync__action_110_guard_clause_110__true -->|next| method_13af2s9_getprofileasync__action_110_guard_clause_110__merge
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__condition -->|continue| method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__false
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__condition -->|exit| method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__true
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__false -->|next| method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__merge
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__merge -->|next| method_13af2s9_getprofileasync__action_113_getprofileasync_repository_read_113_1__linear
    method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__true -->|next| method_13af2s9_getprofileasync__action_111_getprofileasync_guard_clause_111_0__merge
    method_13af2s9_getprofileasync__action_113_extraction_113__linear -->|next| method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__condition
    method_13af2s9_getprofileasync__action_113_getprofileasync_repository_read_113_1__linear -->|next| method_13af2s9_getprofileasync__action_113_extraction_113__linear
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__condition -->|continue| method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__false
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__condition -->|exit| method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__true
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__false -->|next| method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__merge
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__merge -->|next| method_13af2s9_getprofileasync__action_114_guard_clause_114__condition
    method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__true -->|next| method_13af2s9_getprofileasync__action_114_getprofileasync_guard_clause_114_2__merge
    method_13af2s9_getprofileasync__action_114_guard_clause_114__condition -->|continue| method_13af2s9_getprofileasync__action_114_guard_clause_114__false
    method_13af2s9_getprofileasync__action_114_guard_clause_114__condition -->|missing id -> return fail| method_13af2s9_getprofileasync__action_114_guard_clause_114__true
    method_13af2s9_getprofileasync__action_114_guard_clause_114__false -->|next| method_13af2s9_getprofileasync__action_114_guard_clause_114__merge
    method_13af2s9_getprofileasync__action_114_guard_clause_114__merge -->|next| method_13af2s9_getprofileasync__action_116_getprofileasync_await_116_3__await
    method_13af2s9_getprofileasync__action_114_guard_clause_114__true -->|next| method_13af2s9_getprofileasync__action_114_guard_clause_114__merge
    method_13af2s9_getprofileasync__action_116_external_call_116__linear -->|new GetUserProfileQuery userId -> userId string| method_13af2s9_getprofileasync__call_116_GetUserProfileQuery
    method_13af2s9_getprofileasync__action_116_getprofileasync_await_116_3__await -->|next| method_13af2s9_getprofileasync__action_116_external_call_116__linear
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__condition -->|continue| method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__false
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__condition -->|exit| method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__true
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__false -->|next| method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__merge
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__merge -->|return| method_13af2s9_getprofileasync__action_119_getprofileasync_return_119_5__return
    method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__true -->|next| method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__merge
    method_13af2s9_getprofileasync__action_117_guard_clause_117__condition -->|successful -> return profile| method_13af2s9_getprofileasync__action_117_guard_clause_117__false
    method_13af2s9_getprofileasync__action_117_guard_clause_117__condition -->|query failed -> return fail| method_13af2s9_getprofileasync__action_117_guard_clause_117__true
    method_13af2s9_getprofileasync__action_117_guard_clause_117__false -->|next| method_13af2s9_getprofileasync__action_117_guard_clause_117__merge
    method_13af2s9_getprofileasync__action_117_guard_clause_117__merge -->|next| method_13af2s9_getprofileasync__action_117_getprofileasync_guard_clause_117_4__condition
    method_13af2s9_getprofileasync__action_117_guard_clause_117__true -->|next| method_13af2s9_getprofileasync__action_117_guard_clause_117__merge
    method_13af2s9_getprofileasync__call_116_GetUserProfileQuery -->|next| method_13af2s9_getprofileasync__action_117_guard_clause_117__condition
    method_13af2s9_getprofileasync__entry -->|next| method_13af2s9_getprofileasync__action_110_guard_clause_110__condition
```

## Diagram Validation

- Status: warn
- Warning: Control-flow extraction left 1 unresolved jumps.
- Warning: control-flow: diagram method_1pi9wuc_loginasync__fragment_diagram exceeds preferred complexity thresholds (42 nodes, 47 edges).
- Warning: control-flow: diagram method_1ekb3x6_registerasync__fragment_diagram exceeds preferred complexity thresholds (20 nodes, 21 edges).
- Warning: control-flow: diagram method_13af2s9_getprofileasync__fragment_diagram exceeds preferred complexity thresholds (31 nodes, 36 edges).
