Skip to content

Split authentication hooks into appropriate files#1607

Merged
MarceloRGonc merged 12 commits intomainfrom
mg/OPS-3003-5
Nov 13, 2025
Merged

Split authentication hooks into appropriate files#1607
MarceloRGonc merged 12 commits intomainfrom
mg/OPS-3003-5

Conversation

@MarceloRGonc
Copy link
Copy Markdown
Contributor

Part of OPS-3003.

@linear
Copy link
Copy Markdown

linear Bot commented Nov 12, 2025

@MarceloRGonc MarceloRGonc changed the title Split authentication hooks in proper files Split authentication hooks into appropriate files Nov 12, 2025
import { userService } from '../../user/user-service';
import { accessTokenManager } from './access-token-manager';

export async function getProjectAndToken(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved from community-authentication-hooks.ts

email,
password,
});
assertValidEmail(email);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved from community-authentication-hooks.ts

import { organizationService } from '../../organization/organization.service';
import { userService } from '../../user/user-service';

export async function assignDefaultOrganization(user: User): Promise<void> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved from community-authentication-hooks.ts

@MarceloRGonc MarceloRGonc marked this pull request as ready for review November 12, 2025 17:23

await expect(
createUser({ ...baseParams, password: 'abc' }),
createUser({ ...baseParams, password: 'abcas2esf' }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

was this change necessary haha

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was because the password needs 8 char.

Base automatically changed from mg/OPS-3003-4 to main November 13, 2025 08:27
Copilot AI review requested due to automatic review settings November 13, 2025 08:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the authentication service by extracting authentication hooks into dedicated, purpose-specific files. The changes eliminate the hooks pattern in favor of direct function calls, moving core authentication logic into separate modules for user creation, organization assignment, and project context creation.

Key Changes:

  • Removed the authentication hooks system (AuthenticationServiceHooks, communityAuthenticationServiceHooks) and replaced it with direct function calls
  • Extracted user creation logic into create-user.ts with comprehensive test coverage
  • Moved the Provider enum from internal hooks to the shared package for broader accessibility

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/shared/src/lib/authentication/model/authentication-type.ts Adds new Provider enum to shared package
packages/shared/src/lib/authentication/dto/sign-up-request.ts Removes unused referringUserId field from sign-up request
packages/shared/src/index.ts Exports new authentication-type module
packages/server/api/test/unit/authentication/new-user/create-user.test.ts Adds comprehensive unit tests for user creation functions
packages/server/api/test/integration/ce/authentication/signup.test.ts Removes obsolete imports after hooks removal
packages/server/api/test/helpers/mocks/authn.ts Removes referringUserId from mock sign-up request
packages/server/api/src/app/user/user-service.ts Updates delete method to handle nullable organizationId
packages/server/api/src/app/database/seeds/seed-admin.ts Updates Provider import to use shared package
packages/server/api/src/app/database/seeds/dev-seeds.ts Updates Provider import to use shared package
packages/server/api/src/app/authentication/new-user/organization-assignment.ts Extracts organization assignment logic from hooks
packages/server/api/src/app/authentication/new-user/create-user.ts Extracts user creation logic with validation and rollback handling
packages/server/api/src/app/authentication/context/create-project-auth-context.ts Extracts project context creation from hooks
packages/server/api/src/app/authentication/authentication.controller.ts Updates Provider import to use shared package
packages/server/api/src/app/authentication/authentication-service/index.ts Simplifies authentication service by removing hooks and using extracted functions
packages/server/api/src/app/authentication/authentication-service/hooks/index.ts Removes hooks registration system
packages/server/api/src/app/authentication/authentication-service/hooks/community-authentication-hooks.ts Removes community-specific hooks implementation
packages/server/api/src/app/authentication/authentication-service/hooks/authentication-service-hooks.ts Removes hooks interface and Provider enum

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sonarqubecloud
Copy link
Copy Markdown

@MarceloRGonc MarceloRGonc merged commit c98d931 into main Nov 13, 2025
21 checks passed
@MarceloRGonc MarceloRGonc deleted the mg/OPS-3003-5 branch November 13, 2025 08:51
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.

3 participants