From 2940d20e06ba22b7f542ac7dcb20606a28d47173 Mon Sep 17 00:00:00 2001 From: Michael Abebe Date: Mon, 18 May 2026 11:07:09 +0300 Subject: [PATCH] fix:(freight:auth): finished integrating the freight api with the freight portal --- apps/edr-freight-api/.env.example | 3 +++ apps/edr-freight-api/src/app.module.ts | 14 ++++++++++---- apps/edr-freight-web/portal/src/main.tsx | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/apps/edr-freight-api/.env.example b/apps/edr-freight-api/.env.example index 8e19ed4f7..5f2d2b8ee 100644 --- a/apps/edr-freight-api/.env.example +++ b/apps/edr-freight-api/.env.example @@ -14,6 +14,9 @@ JWT_SECRET= JWT_ACCESS_TOKEN_SECRET= JWT_REFRESH_TOKEN_SECRET= JWT_EXPIRES_IN=3600 +# JWT expiry for @tria-plc/api-common token utils (jsonwebtoken timespan format) +JWT_ACCESS_TOKEN_EXPIRES=1h +JWT_REFRESH_TOKEN_EXPIRES=7d # IAM seed defaults (used by @tria-plc/iamapi-common on first boot) SUPER_ADMIN_EMAIL=superadmin@tria.com diff --git a/apps/edr-freight-api/src/app.module.ts b/apps/edr-freight-api/src/app.module.ts index 7b21e906e..8cde48e15 100644 --- a/apps/edr-freight-api/src/app.module.ts +++ b/apps/edr-freight-api/src/app.module.ts @@ -1,7 +1,7 @@ -import { Module } from "@nestjs/common"; +import { Module, OnApplicationBootstrap } from "@nestjs/common"; import { ConfigModule, ConfigService } from "@nestjs/config"; import { TypeOrmModule, TypeOrmModuleOptions } from "@nestjs/typeorm"; -import { IamModule } from "@tria-plc/iamapi-common"; +import { IamModule, DataSeeder } from "@tria-plc/iamapi-common"; import { SharedAuthModule } from "@tria-plc/api-common/modules/auth/shared-auth.module"; import appConfig from "./config/app.config"; @@ -27,7 +27,7 @@ import { NotificationsModule } from "./modules/notifications/notifications.modul config.get("database")!, }), SharedAuthModule, - IamModule, + IamModule.forRoot(), BookingsModule, ConsignmentsModule, TrainsModule, @@ -37,4 +37,10 @@ import { NotificationsModule } from "./modules/notifications/notifications.modul NotificationsModule, ], }) -export class AppModule {} +export class AppModule implements OnApplicationBootstrap { + constructor(private readonly seeder: DataSeeder) {} + + async onApplicationBootstrap() { + await this.seeder.run(); + } +} diff --git a/apps/edr-freight-web/portal/src/main.tsx b/apps/edr-freight-web/portal/src/main.tsx index 09408f6ec..665a9fc81 100644 --- a/apps/edr-freight-web/portal/src/main.tsx +++ b/apps/edr-freight-web/portal/src/main.tsx @@ -10,6 +10,7 @@ import { BrandingProvider, configureIam, UserProvider, + axiosInstance, } from "@tria-plc/iamui-common"; const queryClient = new QueryClient(); @@ -17,6 +18,21 @@ window.__IAM_CONFIG__ = { apiUrl: `${import.meta.env.VITE_BASE_API_URL}/api`, postLoginPath: "/", }; + +// Unwrap the StandardResponse envelope ({ success, data, timestamp }) that the +// freight API's ResponseTransformInterceptor adds to every response, so that +// iamui-common can read response.data.token / response.data fields as expected. +axiosInstance.interceptors.response.use((response) => { + if ( + response.data && + typeof response.data === "object" && + "success" in response.data && + "data" in response.data + ) { + response.data = response.data.data; + } + return response; +}); window.__USER_MANAGEMENT_BRANDING__ = { organizationName: "EDR Platform", appName: "EDR Portal",