Skip to content

Commit 10985cf

Browse files
authored
Add authentication service factory for extensibility (#1737)
Part of OPS-3009. This refactoring allows for easier extension and customization of authentication behavior while preserving type safety and maintaining backward compatibility.
1 parent e9b82a8 commit 10985cf

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AuthenticationResponse } from '@openops/shared';
2+
import { authenticationService } from './basic/authentication-service';
3+
import { SignInParams, SignUpParams } from './types';
4+
5+
export type AuthenticationService = {
6+
signUp(params: SignUpParams): Promise<AuthenticationResponse>;
7+
signIn(request: SignInParams): Promise<AuthenticationResponse>;
8+
};
9+
10+
export function getAuthenticationService(): AuthenticationService {
11+
return authenticationService;
12+
}

packages/server/api/src/app/authentication/authentication.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { analyticsDashboardService } from '../openops-analytics/analytics-dashbo
1616
import { resolveOrganizationIdForAuthnRequest } from '../organization/organization-utils';
1717
import { userService } from '../user/user-service';
1818
import { analyticsAuthenticationService } from './analytics-authentication-service';
19-
import { authenticationService } from './basic/authentication-service';
19+
import { getAuthenticationService } from './authentication-service-factory';
2020
import {
2121
removeAuthCookies,
2222
setAuthCookies,
@@ -100,7 +100,7 @@ const signUpRoute = async (request: any, reply: any) => {
100100
});
101101
}
102102

103-
const signUpResponse = await authenticationService.signUp({
103+
const signUpResponse = await getAuthenticationService().signUp({
104104
...request.body,
105105
verified: edition === OpsEdition.COMMUNITY,
106106
organizationId: null,
@@ -117,7 +117,7 @@ const signInRoute = async (request: any, reply: any) => {
117117
request,
118118
);
119119

120-
const signInResponse = await authenticationService.signIn({
120+
const signInResponse = await getAuthenticationService().signIn({
121121
email: request.body.email,
122122
password: request.body.password,
123123
organizationId,

packages/server/api/src/app/database/seeds/dev-seeds.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { logger, SharedSystemProp, system } from '@openops/server-shared';
22
import { EnvironmentType, Provider } from '@openops/shared';
3-
import { authenticationService } from '../../authentication/basic/authentication-service';
3+
import { getAuthenticationService } from '../../authentication/authentication-service-factory';
44
import { FlagEntity } from '../../flags/flag.entity';
55
import { databaseConnection } from '../database-connection';
66

@@ -30,7 +30,7 @@ const seedDevUser = async (): Promise<void> => {
3030
const DEV_EMAIL = 'dev@openops.com';
3131
const DEV_PASSWORD = '12345678';
3232

33-
await authenticationService.signUp({
33+
await getAuthenticationService().signUp({
3434
email: DEV_EMAIL,
3535
password: DEV_PASSWORD,
3636
firstName: 'Dev',

0 commit comments

Comments
 (0)