Skip to content

Authentication Identity facade service #3437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 28, 2025
Merged

Authentication Identity facade service #3437

merged 12 commits into from
May 28, 2025

Conversation

CarsonF
Copy link
Member

@CarsonF CarsonF commented May 19, 2025

This creates an Identity service to be the facade for all authentication functionality that is sanctioned across the codebase.
With the hope that the auth internals can be decoupled and split apart for more sanity.

This also begins the move into ~/core

I was going for a sibling to Privileges with the name Identity, but I know the name doesn't feel very service-y.

This consolidates functionality as much as possible into this service usage,
including replacing the @AnonymousSession() & @LoggedInSession() decorators.

CarsonF added 6 commits May 19, 2025 12:24
In ~/core.

Migrate SessionHost consumers to this facade.
This moves all session creations into the service.
This should be replaced with something else later.
Other entry points (migrations, etc) should declare something explicit.
Copy link

coderabbitai bot commented May 19, 2025

📝 Walkthrough
## Walkthrough

This change refactors the codebase to centralize session and identity management through a new `Identity` service, replacing direct usage of `SessionHost` and related session utilities. All session access, user context checks, and role-based execution now use the `Identity` abstraction. Supporting code, dependency injection, and method signatures are updated accordingly across modules and services.

## Changes

| Files/Paths (grouped)                                                                                         | Change Summary |
|---------------------------------------------------------------------------------------------------------------|---------------|
| `src/core/authentication/identity.service.ts`, `src/core/authentication/index.ts`                             | Introduced and exported a new `Identity` service class, providing centralized session and identity access, role/user context execution, and admin/self checks. |
| `src/common/session.ts`                                                                                       | Removed all session-related runtime logic, decorators, and utility functions (`loggedInSession`, `SessionPipe`, `LoggedInSession`, `AnonSession`, `addScope`, `isAdmin`); now only exports the `Session` interface and types. |
| `src/components/authentication/authentication.module.ts`                                                      | Added `Identity` to providers and exports arrays, making it injectable and available across modules; removed `SessionPipe` provider. |
| `src/components/authentication/authentication.service.ts`                                                     | Added `asRole<R>(role, fn)` method to execute functions under a synthetic session for a specific role. |
| `src/components/authorization/policy/executor/edge-privileges.ts`, `src/components/authorization/policy/executor/resource-privileges.ts` | Changed session context for permission checks from `SessionHost` to `Identity`. |
| `src/components/authorization/policy/executor/policy-dumper.ts`                                               | Refactored to use `identity.asRole` for permission resolution; updated constructor to inject `Identity`. |
| `src/components/authorization/policy/executor/policy-executor.ts`, `src/components/authorization/policy/executor/privileges.ts` | Replaced all `SessionHost` usage with `Identity` for session context; updated constructors accordingly. |
| `src/components/comments/comment.service.ts`                                                                  | Replaced `SessionHost` and `isAdmin` with `Identity` for thread security and admin checks. |
| `src/components/engagement/engagement.rules.ts`                                                               | Switched from `SessionHost` to `Identity` for session context in engagement rules. |
| `src/components/file/file.service.ts`                                                                         | Added `@Inject(forwardRef(() => MediaService))` to `mediaService` parameter for circular dependency resolution. |
| `src/components/file/media/media.service.ts`                                                                  | Changed import path for `IEventBus` to `~/core/events`. |
| `src/components/notification-system/system-notification.resolver.ts`                                          | Replaced session-based admin check with privilege-based authorization; injected `Privileges` service; removed session parameter from mutation. |
| `src/components/periodic-report/periodic-report.resolver.ts`                                                  | Removed session parameters and admin/anonymous checks from resolver signatures; injected `Identity` and enforce admin check internally. |
| `src/components/periodic-report/periodic-report.service.ts`                                                   | Injected `Identity`; no other logic changes. |
| `src/components/post/post.service.ts`                                                                         | Injected `Identity`; added anonymous user check to return redacted list early. |
| `src/components/post/postable.resolver.ts`                                                                    | Removed session parameter and anonymous session decorator; removed anonymous user check. |
| `src/components/progress-report/media/handlers/update-media-metadata-check.handler.ts`                        | Removed `SessionHost` dependency from constructor. |
| `src/components/progress-report/workflow/handlers/progress-report-workflow-notification.handler.ts`           | Replaced `AuthenticationService` with `Identity` for user context execution. |
| `src/components/project/project.service.ts`                                                                   | Switched from `SessionHost`/`isAdmin` to `Identity` for impersonator admin checks and session context. |
| `src/components/project/workflow/handlers/project-workflow-notification.handler.ts`                           | Unified user/session context management under `Identity`, replacing `AuthenticationService` and `SessionHost`. |
| `src/components/prompts/prompt-variant-response.service.ts`                                                   | Replaced `SessionHost` with `Identity` for session context. |
| `src/components/user/education/education.resolver.ts`                                                         | Changed class decorator from `@Injectable()` to `@Resolver()`. |
| `src/components/user/education/education.service.ts`, `src/components/user/unavailability/unavailability.service.ts` | Replaced `SessionHost` with `Identity`; updated self-check logic in update methods. |
| `src/components/user/user.service.ts`                                                                         | Changed injected session context from `SessionHost` to `Identity`. |
| `src/components/workflow/permission.serializer.ts`, `src/components/workflow/workflow.service.ts`              | Refactored privilege checks and serialization to use `Identity` instead of `SessionHost` and direct session objects. |
| `src/core/data-loader/data-loader.config.ts`                                                                  | Changed session context injection from `SessionHost` to `Identity`. |
| `src/core/database/database.service.ts`                                                                       | Replaced `SessionHost` with injected `Identity` (using `forwardRef`); updated user context in queries. |
| `src/core/gel/gel.service.ts`                                                                                 | Changed session context and cloning logic from `SessionHost` to `Identity`. |
| `src/core/graphql/graphql-tracing.plugin.ts`                                                                  | Changed session context injection from `SessionHost` to `Identity`. |
| `src/core/resources/resource.loader.ts`                                                                       | Replaced `AuthenticationService` with `Identity`; updated CLI readiness logic. |
| `src/components/authentication/session.interceptor.ts`                                                        | Replaced `loggedInSession` verification with `Identity.verifyLoggedIn` method; injected `Identity`. |
| `src/components/comments/comment-thread.resolver.ts`                                                          | Removed session parameter and decorator; replaced logged-in verification with `Identity.verifyLoggedIn`. |
| `src/components/file/file-url.controller.ts`                                                                   | Replaced session verification function with `Identity.verifyLoggedIn`; injected `Identity`. |
| `src/components/authentication/extra-info.resolver.ts`                                                        | Removed session parameter and decorator from method signature. |
| `src/components/authentication/login.resolver.ts`                                                             | Removed session parameter from logout method; injected `SessionHost` to retrieve current session internally. |
| `src/components/changeset/changeset-aware.resolver.ts`, `src/components/changeset/changeset.resolver.ts`       | Removed session parameters; injected `Identity`; replaced anonymous checks with `Identity.isAnonymous`. |
| `src/components/comments/commentable.resolver.ts`                                                             | Injected `Identity`; removed session parameter; replaced anonymous check with `Identity.isAnonymous`. |
| `src/components/file/file-node.resolver.ts`                                                                    | Removed session parameter from `parents` resolver method. |
| `src/components/notifications/notification.resolver.ts`                                                       | Injected `Identity`; removed session parameter; replaced anonymous check with `Identity.isAnonymous`. |
| `src/components/pin/pin.resolver.ts`                                                                           | Injected `Identity`; removed session parameter; replaced anonymous check with `Identity.isAnonymous`. |
| `src/components/product-progress/create-product-connection.resolver.ts`                                       | Injected `Identity`; removed session parameter; replaced anonymous check with `Identity.isAnonymous`. |
| `src/components/project/financial-approver/financial-approver.resolver.ts`                                     | Injected `Identity`; removed session parameter; replaced anonymous check with `Identity.isAnonymous`. |
| `src/components/user/assignable-roles.resolver.ts`                                                             | Removed session parameter from resolver method. |
| `src/components/user/user.resolver.ts`                                                                         | Injected `Identity`; removed session parameter; replaced anonymous check with `Identity.isAnonymous`. |
| `src/common/index.ts`                                                                                           | Removed exports of `LoggedInSession` and `AnonSession` from the session barrel; only `Session` type exported. |

## Possibly related PRs

- [SeedCompany/cord-api-v3#3427](https://github.com/SeedCompany/cord-api-v3/pull/3427): Introduces the `SessionHost` service using AsyncLocalStorage for global session context, which is directly refactored and superseded by the new `Identity` abstraction in this PR.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e079182 and 64fb40a.

📒 Files selected for processing (3)
  • src/common/index.ts (1 hunks)
  • src/common/session.ts (0 hunks)
  • src/components/authentication/authentication.module.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • src/common/session.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/authentication/authentication.module.ts
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: Unit
  • GitHub Check: Generate (head)
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: Generate (base)
  • GitHub Check: lint
  • GitHub Check: Clean
🔇 Additional comments (1)
src/common/index.ts (1)

52-52: LGTM: Simplified session exports align with Identity service introduction

The change to export only the Session type (removing LoggedInSession and AnonSession exports) is consistent with the centralization of authentication functionality in the new Identity service. This is a good step toward decoupling and modularizing authentication internals as stated in the PR objectives.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
src/core/authentication/identity.service.ts (5)

12-15: Consider simplifying the AuthenticationService injection

The & {} empty intersection in the type definition for auth seems unnecessary and could be removed for clarity.

-private readonly auth: AuthenticationService & {},
+private readonly auth: AuthenticationService,

29-61: Consider using @deprecated for discouraged APIs

While you explicitly document that these properties are "not the best API" and "use is discouraged", it would be more effective to mark them with the @deprecated decorator. This would provide IDE warnings to developers using these properties and make the migration path clearer.

/**
 * Is the current requestor anonymous (not logged in)?
 *
 * Not the best API, use is discouraged.
 * Prefer using Auth Policies / {@link Privileges}`.for.can()`
 */
+@deprecated('Use Auth Policies or Privileges.for.can() instead')
get isAnonymous() {
  return this.current.anonymous;
}

77-82: Fix grammatical error in comment

The method comment has a small grammatical error.

/**
- * Run this function with the current user as an ephemeral one this role
+ * Run this function with the current user as an ephemeral one with this role
 */
asRole<R>(role: Role, fn: () => R): R {
  return this.auth.asRole(role, fn);
}

1-4: Consider consistent import paths

The file mixes relative paths ('../../components/authentication') with absolute paths ('~/common'). Consider using absolute paths consistently for better maintainability.

import { forwardRef, Inject, Injectable } from '@nestjs/common';
import type { ID, Role } from '~/common';
-import { type AuthenticationService } from '../../components/authentication';
+import { type AuthenticationService } from '~/components/authentication';
import { SessionHost } from '../../components/authentication/session.host';

1-91: Overall feedback on the Identity service design

The Identity service effectively centralizes authentication functionality while enabling dependency injection and breaking circular dependencies. The facade pattern helps decouple the rest of the codebase from authentication implementation details.

Note that you're creating properties that are immediately documented as discouraged. Consider whether these should be included at all, or if they should be protected/private with alternative public methods that encourage the policy-based approach.

src/components/project/workflow/handlers/project-workflow-notification.handler.ts (2)

35-36: Mismatched logger name

The logger name 'progress-report:status-change-notifier' doesn't match the component (project workflow). Consider using a more appropriate name like 'project:workflow:notification-handler'.

-@Logger('progress-report:status-change-notifier')
+@Logger('project:workflow:notification-handler')

109-109: Consider more explicit handling of external email recipients

The current pattern of using the root user ID as a fallback when notifier.id is null creates an implicit design where external email recipients are processed differently from user recipients. Consider creating a more explicit design, perhaps with a dedicated type for email recipients.

type EmailRecipient = {
  type: 'user' | 'external';
  id?: ID<'User'>;
  email: string;
  // other properties
}

This would make the distinction between user and external recipients more explicit in the code.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d37dd5e and d79b81f.

📒 Files selected for processing (35)
  • src/common/session.ts (2 hunks)
  • src/components/authentication/authentication.module.ts (3 hunks)
  • src/components/authentication/authentication.service.ts (1 hunks)
  • src/components/authorization/policy/executor/edge-privileges.ts (1 hunks)
  • src/components/authorization/policy/executor/policy-dumper.ts (3 hunks)
  • src/components/authorization/policy/executor/policy-executor.ts (4 hunks)
  • src/components/authorization/policy/executor/privileges.ts (4 hunks)
  • src/components/authorization/policy/executor/resource-privileges.ts (1 hunks)
  • src/components/comments/comment.service.ts (3 hunks)
  • src/components/engagement/engagement.rules.ts (5 hunks)
  • src/components/file/file.service.ts (2 hunks)
  • src/components/file/media/media.service.ts (1 hunks)
  • src/components/notification-system/system-notification.resolver.ts (2 hunks)
  • src/components/periodic-report/periodic-report.resolver.ts (1 hunks)
  • src/components/periodic-report/periodic-report.service.ts (3 hunks)
  • src/components/post/post.service.ts (3 hunks)
  • src/components/post/postable.resolver.ts (1 hunks)
  • src/components/progress-report/media/handlers/update-media-metadata-check.handler.ts (0 hunks)
  • src/components/progress-report/workflow/handlers/progress-report-workflow-notification.handler.ts (3 hunks)
  • src/components/project/project.service.ts (5 hunks)
  • src/components/project/workflow/handlers/project-workflow-notification.handler.ts (5 hunks)
  • src/components/prompts/prompt-variant-response.service.ts (3 hunks)
  • src/components/user/education/education.resolver.ts (2 hunks)
  • src/components/user/education/education.service.ts (3 hunks)
  • src/components/user/unavailability/unavailability.service.ts (3 hunks)
  • src/components/user/user.service.ts (3 hunks)
  • src/components/workflow/permission.serializer.ts (2 hunks)
  • src/components/workflow/workflow.service.ts (3 hunks)
  • src/core/authentication/identity.service.ts (1 hunks)
  • src/core/authentication/index.ts (1 hunks)
  • src/core/data-loader/data-loader.config.ts (2 hunks)
  • src/core/database/database.service.ts (4 hunks)
  • src/core/gel/gel.service.ts (4 hunks)
  • src/core/graphql/graphql-tracing.plugin.ts (2 hunks)
  • src/core/resources/resource.loader.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • src/components/progress-report/media/handlers/update-media-metadata-check.handler.ts
🧰 Additional context used
🧬 Code Graph Analysis (8)
src/components/prompts/prompt-variant-response.service.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
src/components/authorization/policy/executor/privileges.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
src/components/authorization/policy/executor/policy-executor.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
src/components/periodic-report/periodic-report.service.ts (1)
src/common/exceptions/unauthorized.exception.ts (1)
  • UnauthorizedException (9-102)
src/components/authentication/authentication.service.ts (2)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
src/common/id-field.ts (1)
  • ID (24-25)
src/components/project/project.service.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
src/components/engagement/engagement.rules.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
src/components/project/workflow/handlers/project-workflow-notification.handler.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: Generate (head)
  • GitHub Check: lint
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: Generate (base)
  • GitHub Check: Clean
  • GitHub Check: Unit
🔇 Additional comments (70)
src/components/file/media/media.service.ts (1)

12-12: Import path updated to use more specific module

This change correctly updates the import path for IEventBus from the general core module to the more specific events module. This aligns with the overall refactoring goal of improving modularity.

src/core/authentication/index.ts (1)

1-1: Good facade pattern implementation

This export statement properly exposes the new Identity service through the authentication module, following the facade pattern described in the PR objectives. This allows other parts of the application to use the Identity service without knowing its implementation details.

src/components/user/education/education.resolver.ts (1)

1-1: Improved GraphQL resolver pattern

The change from @Injectable() to @Resolver() aligns with NestJS best practices for GraphQL resolvers. The @Resolver() decorator is more specific and semantically correct for this use case, properly designating this class as a GraphQL resolver.

Also applies to: 16-16

src/components/authorization/policy/executor/edge-privileges.ts (1)

60-60: Updated to use Identity service instead of SessionHost

This change follows the PR objective of decoupling authentication by using the new Identity facade instead of directly accessing the SessionHost. This centralization of session management will improve maintainability.

src/components/prompts/prompt-variant-response.service.ts (3)

19-19: Import change reflects architecture refactoring

The import change from SessionHost to Identity aligns with the PR objective of centralizing authentication functionality through the new Identity service facade.


56-56: DI updated to use new Identity facade

Dependency injection correctly updated to use the new Identity service instead of SessionHost.


233-233: Session access refactored to use Identity service

Access to the current session has been properly migrated from SessionHost to the Identity facade, maintaining the same functionality while improving architectural organization.

src/components/authorization/policy/executor/resource-privileges.ts (1)

109-109: Session access refactored through Identity service

The change maintains the same behavior while using the new Identity facade to access the current session. This aligns with the authentication centralization effort.

src/components/post/post.service.ts (3)

15-15: Import updated to use Identity facade

The import change aligns with the PR objective of centralizing authentication functionality through the Identity service.


28-28: DI updated to use Identity service

Dependency injection correctly updated to use the new Identity service.


95-98: New anonymous user check using Identity facade

This adds a valuable security check using the new Identity service's isAnonymous property. The TODO comment suggests this should eventually be moved to an authorization policy for better separation of concerns.

Consider implementing this as an authorization policy rule as noted in the TODO comment, which would:

  1. Maintain a cleaner separation of concerns
  2. Centralize authorization logic
  3. Apply the rule consistently across similar scenarios
src/components/user/user.service.ts (3)

12-12: Import updated to use Identity facade

The import change aligns with the PR objective of centralizing authentication functionality.


64-64: DI updated to use Identity service

Dependency injection correctly updated to use the new Identity service instead of SessionHost.


80-80: Session presence check refactored to use Identity

The change maintains the same behavior while leveraging the Identity service's API. This check is important for the role assignment security check that follows.

src/components/workflow/workflow.service.ts (1)

4-4: Appropriate migration to Identity service.

The changes correctly replace the SessionHost dependency with the new Identity service from the core authentication module. This aligns with the PR objective of centralizing authentication functionality.

Also applies to: 23-23, 146-146

src/core/graphql/graphql-tracing.plugin.ts (1)

7-7: Successfully migrated from SessionHost to Identity.

The tracing plugin correctly updates both the dependency injection and usage of the identity context. The reference to currentMaybe?.userId has been properly maintained for user tracking in segments.

Also applies to: 15-15, 50-50

src/components/authorization/policy/executor/policy-executor.ts (1)

5-5: Properly implemented Identity service across policy execution.

The PolicyExecutor class has been successfully updated to use the new Identity service. All references to the current session have been updated, which is critical for this class that handles permission resolution.

Also applies to: 43-43, 67-67, 190-190

src/components/authorization/policy/executor/privileges.ts (1)

9-9: Access control successfully migrated to Identity service.

The Privileges class properly adapts to the new Identity facade. All session references are correctly updated, maintaining the same authorization behavior while using the centralized authentication service.

Also applies to: 26-26, 93-93, 105-105

src/components/authentication/authentication.service.ts (1)

259-268: New method looks good and aligns with service responsibilities

The implementation of asRole follows patterns similar to the existing asUser method but is designed for role-based execution context rather than user-based. The synthetic session setup correctly includes the role with global scope.

src/components/progress-report/workflow/handlers/progress-report-workflow-notification.handler.ts (3)

12-12: Import updated to use the new Identity service

The import change correctly brings in the new Identity facade service from the core authentication module.


39-39: Constructor dependency updated from AuthenticationService to Identity

The constructor parameter has been changed to use the new Identity service, which centralizes authentication functionality.


116-116: Method call updated to use Identity service

The method call has been updated to use this.identity.asUser instead of this.auth.asUser, maintaining the same functionality while leveraging the new facade service.

src/components/authentication/authentication.module.ts (3)

5-5: Import added for Identity service

Correctly imports the new Identity service from the core authentication module.


38-38: Added Identity service to providers

Identity service is now registered as a provider in the module, making it available for dependency injection.


49-49: Exported Identity service from module

The Identity service is now exported from the module, allowing other modules that import AuthenticationModule to access it.

src/core/database/database.service.ts (3)

1-1: Imports updated for Identity service

The imports have been updated to include forwardRef and Inject from NestJS, and the Identity service from the authentication module.

Also applies to: 20-20


67-68: Constructor dependency changed from SessionHost to Identity

The constructor now injects the Identity service using forward reference instead of SessionHost. The forward reference pattern is correctly used to avoid circular dependencies.


128-128: Updated session access to use Identity service

The code now uses this.identity.currentIfInCtx?.userId instead of the previous SessionHost implementation to access the current user ID, maintaining the same functionality.

src/components/file/file.service.ts (1)

5-5: Circular dependency resolution with forwardRef is appropriate.

Adding the forwardRef in the dependency injection decorator addresses a circular dependency between FileService and MediaService. This matches NestJS best practices for resolving circular dependencies.

Also applies to: 63-64

src/common/session.ts (1)

10-10: Good migration from SessionHost to Identity.

The changes to use the new Identity service instead of SessionHost align with the PR objective of centralizing authentication functionality. The Identity service acts as a facade for authentication operations, making session management more modular and maintainable.

Also applies to: 44-44, 47-47

src/components/user/education/education.service.ts (1)

4-4: Improved abstraction using Identity.isSelf()

The replacement of direct session user ID comparison with identity.isSelf() is a cleaner approach. This abstraction encapsulates the user identity verification logic, making the code more maintainable and the authentication checks more consistent across the codebase.

Also applies to: 19-19, 50-50

src/components/engagement/engagement.rules.ts (2)

12-12: Successfully migrated session access to Identity service.

All the instance accesses to sessionHost.current have been properly migrated to use identity.current. This change aligns with the PR objective of centralizing authentication logic in the Identity facade service.

Also applies to: 38-38, 320-320, 360-360, 372-372


320-336:

✅ Verification successful

Verify session logic for available transitions is preserved.

The session checking logic to determine available transitions now uses the Identity service. Since this is workflow-critical code, ensure the behavior remains consistent under the new implementation.


🏁 Script executed:

#!/bin/bash
# Verify all sessionHost.current usages have been replaced with identity.current
rg "sessionHost\.current" --type ts

Length of output: 896


Session logic unchanged via IdentityService proxy

IdentityService.current (in src/core/authentication/identity.service.ts) directly returns sessionHost.current, so using this.identity.current in engagement.rules.ts preserves the original session behavior. No further changes are required.

src/core/data-loader/data-loader.config.ts (3)

7-7: Import change looks good!

The import has been updated from SessionHost to Identity as part of the authentication facade refactoring.


14-14: Constructor parameter change is correct

The dependency injection has been properly updated to use the new Identity service instead of SessionHost.


30-30: Session access updated correctly

The session retrieval logic has been successfully migrated from sessionHost.currentMaybe to identity.currentMaybe, maintaining the same functionality while using the new abstraction.

src/components/user/unavailability/unavailability.service.ts (3)

4-4: Import updated correctly

The import has been updated to use the new Identity service from the core authentication module.


19-19: Constructor dependency properly updated

The service now correctly injects the Identity service instead of SessionHost.


49-49: Good authorization improvement

The authorization check has been refactored to use the isSelf method from the Identity service, which is cleaner and more maintainable than the previous direct comparison.

src/components/periodic-report/periodic-report.service.ts (3)

10-10: New imports are appropriate

The imports for UnauthorizedException and Identity have been correctly added to support the new authorization check.

Also applies to: 14-14


40-40: Constructor dependency properly added

The Identity service is now correctly injected into the constructor.


119-123: Admin check implementation looks good

The implementation correctly enforces that only admins can list periodic reports by checking identity.isAdmin. The TODO comment acknowledges that this should eventually be moved to an auth policy.

src/core/gel/gel.service.ts (4)

9-9: Import updated correctly

The import has been updated to use the new Identity service.


26-26: Constructor updated properly

The service now correctly injects the Identity service instead of SessionHost.


37-37: Clone method updated correctly

The clone method has been updated to pass the identity service to the new instance.


118-118: Session access updated correctly

The code now correctly retrieves the current user ID through identity.currentIfInCtx?.userId while maintaining the same behavior and UUID check.

src/components/workflow/permission.serializer.ts (1)

2-3: Well-implemented Identity service integration

The changes effectively replace direct session manipulation with the new Identity facade, using identity.asRole() to execute privilege checks in the context of different roles. This aligns perfectly with the PR's goal of centralizing authentication functionality and improves the code's clarity.

Also applies to: 14-18

src/components/post/postable.resolver.ts (2)

3-3: Clean removal of session-related imports

The import statement has been simplified, removing unused imports related to session handling, which aligns with the move toward the centralized Identity service approach.


17-38: Improved separation of concerns

The resolver has been simplified by removing session handling logic. The authorization check for anonymous users has likely been moved to the service layer, which is a better separation of concerns. This makes the resolver more focused on its primary responsibility of orchestrating data fetching.

src/components/notification-system/system-notification.resolver.ts (1)

10-10: Effective privilege-based authorization implementation

The code has been improved by replacing direct session-based admin checks with a more declarative privilege-based approach. This change:

  1. Makes the authorization intent clearer (verifyCan('create') vs checking admin status)
  2. Improves separation of concerns by delegating authorization logic to the Privileges service
  3. Maintains the same security characteristics while simplifying the resolver

Also applies to: 25-28, 34-34

src/core/resources/resource.loader.ts (2)

1-1: Appropriate dependency injection change

The constructor now properly injects the Identity service instead of the previous AuthenticationService, aligning with the PR's goal of centralizing authentication through the Identity facade.

Also applies to: 8-8, 47-47


114-119: Clean implementation of Identity service methods

The code effectively adapts to the new Identity service interface:

  • identity.readyForCli() replaces the previous authentication preparation for CLI mode
  • Context retrieval logic is refactored for clarity while maintaining the same functionality

This change supports the broader refactoring goal while ensuring the ResourceLoader continues to function correctly in both CLI and normal operation modes.

src/components/periodic-report/periodic-report.resolver.ts (2)

9-9: Import dependencies updated to match service layer authorization changes.

The resolver now imports only what it needs after moving authorization logic to the service layer.


41-47: Authorization handling moved to service layer.

The periodicReports query method signature was simplified by removing the session parameter, aligning with the architectural change that moves authorization checks from resolvers to services. This improves separation of concerns and reduces coupling.

src/components/project/project.service.ts (5)

24-24: Migrated to Identity facade for authentication.

The service now imports the new Identity facade for authentication functionality.


91-91: Injected Identity service instead of SessionHost.

Constructor dependency updated to use the new Identity service, centralizing authentication and session management.


138-146: Simplified admin authorization check.

The admin check is now performed using the more expressive this.identity.isImpersonatorAdmin method instead of manually checking session roles.


159-159: Simplified session access.

Now using this.identity.current to access the current session, which provides a cleaner API than direct session host access.


256-256: Consistent admin authorization pattern.

Using this.identity.isImpersonatorAdmin for admin checks ensures consistent authorization patterns throughout the codebase.

src/components/comments/comment.service.ts (3)

15-15: Migrated to Identity facade for authentication.

The service now imports the new Identity facade for authentication functionality.


41-41: Injected Identity service instead of SessionHost.

Constructor dependency updated to use the new Identity service, centralizing authentication and session management.


124-124: Improved readability of access control logic.

The thread deletion permission check now uses more semantic methods identity.isSelf() and identity.isAdmin, making the code's intent clearer than direct session property checks.

src/components/authorization/policy/executor/policy-dumper.ts (3)

22-26: Updated imports to use Identity facade.

Streamlined imports to use the new Identity service while removing now-unused session-related imports.


42-42: Injected Identity service for role-based execution.

Constructor now injects the Identity service to support contextual execution of permission checks.


171-209: Simplified role-based execution using Identity.

Refactored to use identity.asRole() instead of manually constructing session objects with specific roles. This centralizes the logic for role-based execution and reduces the chance of inconsistencies in how sessions are created across the codebase.

src/components/project/workflow/handlers/project-workflow-notification.handler.ts (5)

12-12: LGTM! Good replacement of AuthenticationService with Identity

The import and injection of the new Identity service looks correct, replacing direct use of AuthenticationService.

Also applies to: 29-29


43-43: Session access through Identity looks good

Correctly retrieving the current session through the Identity facade instead of directly from SessionHost.


76-84: Execution as root user looks correct

The switch to using Identity for user context switching is properly implemented.


110-136: Identity asUser implementation looks good

The switch to using Identity for template property resolution looks correct.


57-63:

❌ Incorrect review comment

Consider checking for anonymous sessions

When filtering notifyees, the code assumes session.userId is present, but doesn't check if the session is anonymous. Consider adding a check:

.filter(
  (n) =>
    // Not current user
-    n.id !== session.userId &&
+    (!session.anonymous && n.id !== session.userId) &&
    // Only email notifications right now
    n.email,
);

🏁 Script executed:

#!/bin/bash
# Check if anonymous sessions are handled elsewhere or if this is a potential issue

# Search for anonymous session handling in notification handlers
echo "Checking for anonymous session handling in notification handlers..."
rg -A 2 "session\.anonymous" --type ts src/components/project/workflow/handlers/

# Search for similar patterns in related notification handlers
echo "Checking similar patterns in other notification handlers..."
fd "notification.handler.ts" --type f --exec rg -A 5 "filter.*session.*userId" {} \;

Length of output: 444


I’d like to inspect how session is defined and where it comes from to confirm whether an anonymous flag exists or is handled elsewhere. Let’s pull in the file context and look for a Session type:


🏁 Script executed:

#!/bin/bash
# Show imports and Session usage in the handler
echo "=== File head ==="
sed -n '1,100p' src/components/project/workflow/handlers/project-workflow-notification.handler.ts

# Search globally for a Session interface/type definition
echo "=== Searching for Session definition ==="
rg --context=3 "interface Session" -t ts
rg --context=3 "type Session" -t ts

# Search the entire codebase for any 'anonymous' mentions
echo "=== Searching for 'anonymous' ==="
rg --context=3 "anonymous" -t ts

Length of output: 34333


No anonymous‐session guard needed in this handler

After digging in:

  • The Session interface does include an anonymous flag, but this event handler only ever runs under authenticated (or system/root) contexts—anonymous sessions are blocked at the GraphQL layer or run as a non‐anonymous “root” inside identity.asUser.
  • No other handlers in *.handler.ts files check for session.anonymous. Adding this guard here would be inconsistent with the rest of our event‐handler patterns.

You can safely ignore the suggestion to filter on session.anonymous.

Likely an incorrect or invalid review comment.

CarsonF added 3 commits May 19, 2025 16:40
These were chaos.
NodeJS just exited, no error or logs.
This crash happened in `Injector.loadInstance`
on the returning the `instanceHost.donePromise`.

I believe the cycle check right above it should have
caught this, but it didn't.

I'm clueless on how node just exited too...
somehow a deadlock or empty event loop somehow?
@CarsonF CarsonF force-pushed the refactor/identity branch from d79b81f to 14b8a78 Compare May 19, 2025 21:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
src/components/file/file-url.controller.ts (2)

41-41: Verify if session parameter is necessary

The session parameter is being passed to verifyLoggedIn(), but the Identity service likely already has access to the current session context.

Consider if this can be simplified to:

-      this.identity.verifyLoggedIn(session);
+      this.identity.verifyLoggedIn();

This would be more consistent with the usage in other files and better encapsulate session management within the Identity service.


44-44: TODO could be addressed with the Identity service

This TODO comment about authorization using session could potentially be addressed now using the new Identity service's authorization capabilities.

Would you like me to suggest an implementation approach for handling authorization using the Identity service?

src/components/authentication/session.interceptor.ts (1)

38-90: Consider refactoring session handling for better separation of concerns

The SessionInterceptor is still doing a lot of complex session management in conjunction with the Identity service. Now that the Identity facade is in place, consider if some of this session hydration and management logic should be migrated into the Identity service for better encapsulation.

This would simplify the interceptor and further consolidate authentication logic in the Identity service, reinforcing its role as the central facade for authentication.

src/components/comments/comment-thread.resolver.ts (1)

47-48: Consider implementing the TODO to move authentication to policy

Now that the Identity service is available, consider implementing the TODO comment about moving this authentication check to an auth policy, which would better separate concerns.

This aligns with your efforts to centralize authentication and would help decouple authorization logic from business logic in the resolver.

src/common/session.ts (1)

34-60: Consider updating deprecation notices with migration guidance

Since the decorators are marked as deprecated, consider enhancing the JSDoc comments to explain how developers should use the Identity service instead.

For example:

- /** @deprecated */
+ /** 
+  * @deprecated Use dependency injection with Identity service instead.
+  * Example: constructor(private readonly identity: Identity) {}
+  * Then use this.identity.verifyLoggedIn() where needed.
+  */
export const LoggedInSession = () => AnonSession();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14b8a78 and 30402ce.

📒 Files selected for processing (5)
  • src/common/session.ts (2 hunks)
  • src/components/authentication/session.interceptor.ts (3 hunks)
  • src/components/comments/comment-thread.resolver.ts (3 hunks)
  • src/components/file/file-url.controller.ts (3 hunks)
  • src/core/authentication/identity.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/authentication/identity.service.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/file/file-url.controller.ts (1)
src/components/authentication/session.resolver.ts (1)
  • session (42-96)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: Unit
  • GitHub Check: Generate (head)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: Clean
  • GitHub Check: Generate (base)
  • GitHub Check: lint
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (12)
src/components/file/file-url.controller.ts (2)

13-13: Appropriate import for the new Identity facade

The import of the Identity facade from the core authentication module shows good organization, aligning with the PR's goal of centralizing authentication functionality.


26-26: Good dependency injection pattern

Properly injecting the Identity service as a private readonly member follows best DI practices and allows for easier testing.

src/components/authentication/session.interceptor.ts (3)

25-25: Appropriate import for the new Identity facade

The import of the Identity facade from the core authentication module shows good organization, aligning with the PR's goal of centralizing authentication functionality.


39-39: Good dependency injection pattern

Properly injecting the Identity service as a private readonly member follows best DI practices and allows for easier testing.


89-89: Concise usage of Identity service

The removal of any explicit session parameter in this call to verifyLoggedIn() is good - it uses the Identity service's internal session context management as intended.

src/components/comments/comment-thread.resolver.ts (3)

5-5: Appropriate import for the new Identity facade

The import of the Identity facade from the core authentication module shows good organization, aligning with the PR's goal of centralizing authentication functionality.


26-26: Good dependency injection pattern

Properly injecting the Identity service as a private readonly member follows best DI practices and allows for easier testing.


48-48: Concise usage of Identity service

The use of this.identity.verifyLoggedIn() without parameters correctly leverages the Identity service's internal session context management.

src/common/session.ts (4)

10-10: Appropriate import for the new Identity facade

The import of the Identity facade from the core authentication module shows good organization, aligning with the PR's goal of centralizing authentication functionality.


36-36: Good dependency injection pattern

Properly injecting the Identity service as a private readonly member follows best DI practices and allows for easier testing.


39-39: Leveraging Identity's session management

Using identity.currentMaybe properly delegates session access to the Identity service.


44-44: Clean deprecation approach

The approach of having LoggedInSession just delegate to AnonSession is clean and maintains backward compatibility while encouraging migration to the new Identity service.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (2)
src/components/user/user.resolver.ts (1)

136-142: 💡 Verification agent

🧩 Analysis chain

Good implementation of session-less authentication check.

The method signature has been simplified by removing the session parameter, and now correctly uses the injected Identity service to check if the user is anonymous. Consider moving this authorization check to an auth policy as mentioned in the TODO comment.


🏁 Script executed:

#!/bin/bash
# Search for similar authentication checks that should also be migrated to auth policies
rg -A 1 -B 1 "this.identity.isAnonymous" --glob "*.ts" | grep "TODO"

Length of output: 804


Consolidate Inline Auth Checks into a Central Policy/Guard

Great work simplifying the userByEmail method and leveraging the injected Identity service. To reduce duplication and improve maintainability, please migrate all scattered this.identity.isAnonymous checks into a shared auth policy or guard. Inline TODOs currently exist in the following files:

  • src/components/pin/pin.resolver.ts // TODO move to DB layer?
  • src/components/user/user.resolver.ts // TODO move to auth policy?
  • src/components/project/financial-approver/financial-approver.resolver.ts // TODO move to auth policy
  • src/components/product-progress/create-product-connection.resolver.ts // TODO move to auth policy
  • src/components/post/post.service.ts // TODO move to auth policy
  • src/components/comments/commentable.resolver.ts // TODO move to auth policy
  • src/components/notifications/notification.resolver.ts // TODO move to DB layer?
  • src/components/changeset/changeset.resolver.ts // TODO move to auth policy
  • src/components/changeset/changeset-aware.resolver.ts // TODO move to auth policy

By centralizing this logic, you’ll ensure consistent behavior across all resolvers/services and make future updates far easier.

src/components/notifications/notification.resolver.ts (1)

19-28: 💡 Verification agent

🧩 Analysis chain

Good implementation of session-less authentication check.

The method signature has been simplified by removing the session parameter, and now correctly uses the injected Identity service to check if the user is anonymous. Consider moving this check to the database layer as mentioned in the TODO comment on line 23.


🏁 Script executed:

#!/bin/bash
# Check for any other similar TODOs that might need to be addressed in a future PR
rg -A 1 -B 1 "TODO move to DB layer" --glob "src/**/*.ts"

Length of output: 520


Refactor anonymous‐user check into the data layer for consistency

The session-less check here looks good, but as noted by the TODO on line 23, this logic belongs in the DB/repository layer rather than in each resolver. We also discovered the identical TODO and isAnonymous guard in src/components/pin/pin.resolver.ts. To keep our code DRY and centralize authentication concerns, please extract and apply this filter in the data-access layer and remove the per-resolver checks.

Files to update:

  • src/components/notifications/notification.resolver.ts (around line 23)
  • src/components/pin/pin.resolver.ts (around the // TODO move to DB layer? comment)

Once the checks live in the DB layer, you can safely delete these resolver guards.

🧹 Nitpick comments (3)
src/components/project/financial-approver/financial-approver.resolver.ts (1)

35-38: Consider following up on the TODO comment

The TODO comment indicates a future improvement to move the anonymous user check to an auth policy. This would be a good follow-up task after this PR is complete to further separate authorization concerns.

src/components/product-progress/create-product-connection.resolver.ts (1)

20-22: Note the recurring TODO pattern

Similar to other files in this PR, there's a TODO about moving the anonymous check to an auth policy. Consider creating a follow-up task to implement these auth policies across all affected components.

src/components/comments/commentable.resolver.ts (1)

40-43: Consider a reusable anonymous user guard

Multiple files in this PR show the same pattern of checking for anonymous users and returning empty/redacted results. Consider creating a reusable guard or policy for this common pattern after completing this refactoring.

// Example of a potential reusable guard
@Injectable()
export class AnonymousGuard implements CanActivate {
  constructor(private readonly identity: Identity) {}

  canActivate(): boolean {
    return !this.identity.isAnonymous;
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30402ce and e079182.

📒 Files selected for processing (14)
  • src/common/session.ts (0 hunks)
  • src/components/authentication/authentication.module.ts (2 hunks)
  • src/components/authentication/extra-info.resolver.ts (2 hunks)
  • src/components/authentication/login.resolver.ts (2 hunks)
  • src/components/changeset/changeset-aware.resolver.ts (2 hunks)
  • src/components/changeset/changeset.resolver.ts (3 hunks)
  • src/components/comments/commentable.resolver.ts (2 hunks)
  • src/components/file/file-node.resolver.ts (1 hunks)
  • src/components/notifications/notification.resolver.ts (2 hunks)
  • src/components/pin/pin.resolver.ts (1 hunks)
  • src/components/product-progress/create-product-connection.resolver.ts (1 hunks)
  • src/components/project/financial-approver/financial-approver.resolver.ts (3 hunks)
  • src/components/user/assignable-roles.resolver.ts (2 hunks)
  • src/components/user/user.resolver.ts (3 hunks)
💤 Files with no reviewable changes (1)
  • src/common/session.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/authentication/authentication.module.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/notifications/notification.resolver.ts (1)
src/common/pagination.input.ts (1)
  • ListArg (118-132)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: E2E Tests (neo4j 6/6)
  • GitHub Check: E2E Tests (neo4j 5/6)
  • GitHub Check: E2E Tests (neo4j 4/6)
  • GitHub Check: E2E Tests (neo4j 3/6)
  • GitHub Check: E2E Tests (neo4j 2/6)
  • GitHub Check: Generate (head)
  • GitHub Check: E2E Tests (neo4j 1/6)
  • GitHub Check: Generate (base)
  • GitHub Check: lint
  • GitHub Check: Unit
  • GitHub Check: Clean
🔇 Additional comments (24)
src/components/file/file-node.resolver.ts (1)

35-35: LGTM: Session parameter successfully removed

The removal of the @AnonSession() decorator and session parameter aligns with the PR objectives of centralizing authentication through the Identity service facade.

src/components/user/assignable-roles.resolver.ts (2)

2-2: LGTM: Import cleanup

Simplified import by removing unused AnonSession and Session types.


13-14: LGTM: Session parameter successfully removed

The assignableRoles resolver method no longer requires an explicit session parameter, aligning with the centralized authentication approach using the Identity service.

src/components/authentication/login.resolver.ts (4)

17-17: LGTM: Import updated

Replaced session-related imports from common with direct import of the SessionHost service.


23-23: LGTM: Session access moved to constructor injection

Properly injected SessionHost service in the constructor to replace session parameter.


47-48: LGTM: Session access refactored

Successfully refactored to access the session via the injected SessionHost service rather than through a parameter.


47-48: Verify if this should use the new Identity service

While other components have been migrated to use the Identity service, this resolver still uses SessionHost directly. Confirm if this is intentional or if it should also be updated to use the Identity service for consistency.

src/components/authentication/extra-info.resolver.ts (2)

3-3: LGTM: Import cleanup

Simplified import by removing unused AnonSession and Session types.


14-14: LGTM: Session parameter successfully removed

The betaFeatures method no longer requires an explicit session parameter, aligning with the centralized authentication approach using the Identity service.

src/components/project/financial-approver/financial-approver.resolver.ts (1)

10-10: Successfully implemented Identity service facade

The changes properly integrate the new Identity service for authentication checks, replacing direct session handling. This aligns well with the PR's goal of centralizing authentication functionality.

Also applies to: 23-23, 36-36

src/components/product-progress/create-product-connection.resolver.ts (1)

2-3: Correctly implemented Identity service pattern

The resolver has been properly updated to use the Identity service instead of session parameters, maintaining consistent patterns with other resolvers in the codebase.

Also applies to: 9-12, 21-21

src/components/pin/pin.resolver.ts (2)

2-3: Successfully migrated to Identity service

The resolver has been properly updated to use the Identity service, following the same pattern as other components in this PR.

Also applies to: 9-12, 25-25


24-26: Different approach for PIN checks

Unlike other files that suggest moving checks to auth policies, this TODO suggests moving the check to the DB layer. This distinction makes sense for PIN functionality which is more about user preferences than authorization.

src/components/comments/commentable.resolver.ts (1)

12-12: Successfully implemented Identity service pattern

The resolver has been properly updated to use the Identity service instead of session parameters, maintaining the same functionality while improving code organization.

Also applies to: 19-22, 41-41

src/components/user/user.resolver.ts (2)

20-20: Good import addition of the Identity service.

This import correctly brings in the new centralized authentication facade service.


74-74: Appropriate dependency injection of Identity service.

This injection provides access to the centralized Identity facade for authentication, aligned with the PR's objective of decoupling authentication logic.

src/components/changeset/changeset-aware.resolver.ts (3)

3-5: Clean import refactoring.

Properly removed the session-related imports and added the Identity service import, which aligns with the centralization of authentication logic.


13-13: Appropriate dependency injection of Identity service.

This injection provides access to the centralized Identity facade for authentication.


52-66:

✅ Verification successful

Good implementation of session-less authentication check.

The method signature has been simplified by removing the session parameter, and the code now correctly uses the injected Identity service to check if the user is anonymous. The call to changesetResolver.difference has also been updated to remove the session parameter.

Consider moving this authentication check to an auth policy as mentioned in the TODO comment on line 55.


🏁 Script executed:

#!/bin/bash
# Check if the changesetResolver.difference method signature has been properly updated
rg -A 3 "async difference\(" --glob "src/components/changeset/*.ts"

Length of output: 710


Session-less auth guard looks solid; difference signature matches updated resolver
File: src/components/changeset/changeset-aware.resolver.ts (lines 52–66)

  • Uses the injected Identity service (identity.isAnonymous) to short-circuit anonymous users
  • Calls changesetResolver.difference(changeset, object.id), which aligns with the removed-session signature in both the resolver and repository layers

Suggestion: Consider moving the identity.isAnonymous check into an auth policy, as noted by the TODO on line 55.

src/components/changeset/changeset.resolver.ts (3)

2-5: Clean import refactoring.

Properly removed the session-related imports and added the Identity service import, which aligns with the centralization of authentication logic.


14-14: Appropriate dependency injection of Identity service.

This injection provides access to the centralized Identity facade for authentication.


26-34: Good simplification of method signature.

The signature has been streamlined by removing the session parameter, which is now handled through the injected Identity service.

src/components/notifications/notification.resolver.ts (2)

2-3: Clean import refactoring.

Properly removed the session-related imports and added the Identity service import, which aligns with the centralization of authentication logic.


14-17: Good dependency injection setup.

The constructor now properly injects both the notification service and the Identity facade.

@CarsonF CarsonF force-pushed the refactor/identity branch from e079182 to 64fb40a Compare May 20, 2025 00:57
@CarsonF CarsonF linked an issue May 27, 2025 that may be closed by this pull request
Copy link
Contributor

@bryanjnelson bryanjnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Progress!

@CarsonF CarsonF merged commit 15812b1 into develop May 28, 2025
18 checks passed
@CarsonF CarsonF deleted the refactor/identity branch May 28, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auth Refactor 2025
2 participants