Skip to content

Commit

Permalink
[#IOPID-1201] add deleteInstallation to lockUserAuthentiction flow
Browse files Browse the repository at this point in the history
  • Loading branch information
gquadrati committed Dec 11, 2023
1 parent c004ee8 commit fa4308d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ export async function newApp({
SESSION_STORAGE,
USER_METADATA_STORAGE,
LOLLIPOP_SERVICE,
AUTHENTICATION_LOCK_SERVICE
AUTHENTICATION_LOCK_SERVICE,
notificationServiceFactory
);
if (FF_BONUS_ENABLED) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
Expand Down Expand Up @@ -1290,15 +1291,17 @@ function registerSessionAPIRoutes(
sessionStorage: RedisSessionStorage,
userMetadataStorage: RedisUserMetadataStorage,
lollipopService: LollipopService,
authenticationLockService: AuthenticationLockService
authenticationLockService: AuthenticationLockService,
notificationServiceFactory: NotificationServiceFactory
): void {
if (FF_ENABLE_SESSION_ENDPOINTS) {
const sessionLockController: SessionLockController =
new SessionLockController(
sessionStorage,
userMetadataStorage,
lollipopService,
authenticationLockService
authenticationLockService,
notificationServiceFactory
);

app.get(
Expand Down
34 changes: 33 additions & 1 deletion src/controllers/sessionLockController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import RedisUserMetadataStorage from "../services/redisUserMetadataStorage";
import AuthenticationLockService, {
NotReleasedAuthenticationLockData,
} from "../services/authenticationLockService";
import { NotificationServiceFactory } from "../services/notificationServiceFactory";

import { UserSessionInfo } from "../../generated/session/UserSessionInfo";
import { AuthLockBody } from "../../generated/session/AuthLockBody";
Expand Down Expand Up @@ -73,7 +74,8 @@ export default class SessionLockController {
private readonly sessionStorage: RedisSessionStorage,
private readonly metadataStorage: RedisUserMetadataStorage,
private readonly lollipopService: LollipopService,
private readonly authenticationLockService: AuthenticationLockService
private readonly authenticationLockService: AuthenticationLockService,
private readonly notificationServiceFactory: NotificationServiceFactory
) {}

/**
Expand Down Expand Up @@ -245,6 +247,7 @@ export default class SessionLockController {
pipe(
AP.sequenceT(TE.ApplicativeSeq)(
...this.buildInvalidateUserSessionTask(fiscalCode),
this.clearInstallation(fiscalCode),
// if clean up went well, lock user session
this.authenticationLockService.lockUserAuthentication(
fiscalCode,
Expand Down Expand Up @@ -414,6 +417,35 @@ export default class SessionLockController {
),
] as const;

private readonly clearInstallation = (fiscalCode: FiscalCode) =>
// async fire & forget
pipe(
TE.tryCatch(
() =>
this.notificationServiceFactory(fiscalCode).deleteInstallation(
fiscalCode
),
(err) =>
Error(
`Cannot delete Notification Installation: ${JSON.stringify(err)}`
)
),
TE.chainW(
flow(
TE.fromPredicate(
(response) => response.kind === "IResponseSuccessJson",
(err) =>
Error(
`Cannot delete Notification Installation: ${
err.detail ?? "Not Defined"
}`
)
),
TE.map(() => true)
)
)
);

private readonly unlockuserAuthenticationLockData = (
fiscalCode: FiscalCode,
maybeUnlockCode: O.Option<UnlockCode>,
Expand Down

0 comments on commit fa4308d

Please sign in to comment.