From a6592ed8e3aa872a588719f32f6949c78bdc1915 Mon Sep 17 00:00:00 2001 From: alexeh Date: Fri, 18 Oct 2024 05:05:22 +0200 Subject: [PATCH] use common API_URL --- admin/index.ts | 1 + admin/providers/auth.provider.ts | 3 +-- admin/resources/users/user.actions.ts | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/admin/index.ts b/admin/index.ts index dee457e0..38aedac7 100644 --- a/admin/index.ts +++ b/admin/index.ts @@ -16,6 +16,7 @@ AdminJS.registerAdapter({ }); const PORT = 1000; +export const API_URL = process.env.API_URL || "http://localhost:4000"; const componentLoader = new ComponentLoader(); const authProvider = new AuthProvider(); diff --git a/admin/providers/auth.provider.ts b/admin/providers/auth.provider.ts index 90a3a6e3..e8850787 100644 --- a/admin/providers/auth.provider.ts +++ b/admin/providers/auth.provider.ts @@ -2,8 +2,7 @@ import { BaseAuthProvider, LoginHandlerOptions } from "adminjs"; import { ROLES } from "@shared/entities/users/roles.enum.js"; import { UserDto, UserWithAccessToken } from "@shared/dtos/users/user.dto.js"; - -const API_URL = process.env.API_URL || "http://localhost:4000"; +import { API_URL } from "../index.js"; export class AuthProvider extends BaseAuthProvider { override async handleLogin(opts: LoginHandlerOptions, context?: any) { diff --git a/admin/resources/users/user.actions.ts b/admin/resources/users/user.actions.ts index 3601c354..5fe2e058 100644 --- a/admin/resources/users/user.actions.ts +++ b/admin/resources/users/user.actions.ts @@ -1,7 +1,6 @@ import { ActionContext, ActionRequest, ActionResponse } from "adminjs"; import { CreateUserDto } from "@shared/dtos/users/create-user.dto.js"; - -const API_URL = process.env.API_URL || "http://localhost:4000"; +import { API_URL } from "../../index.js"; export const createUserAction = async ( request: ActionRequest, @@ -13,6 +12,9 @@ export const createUserAction = async ( const { email, role, name, partnerName } = request.payload as CreateUserDto; const record = resource.build({ email, role, name }); const accessToken = currentAdmin?.accessToken; + if (!accessToken) { + throw new Error("Current Admin token not found"); + } try { const apiResponse = await fetch(`${API_URL}/admin/users`, { method: "POST",