From 2862c94954b3c4fa5a698bd545b7e45ced7336ae 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 ++++-- admin/resources/users/user.resource.ts | 1 + 4 files changed, 7 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", diff --git a/admin/resources/users/user.resource.ts b/admin/resources/users/user.resource.ts index 99fff6d9..19f70e44 100644 --- a/admin/resources/users/user.resource.ts +++ b/admin/resources/users/user.resource.ts @@ -15,6 +15,7 @@ export const userResource: ResourceWithOptions = { isActive: { isVisible: false }, email: { isRequired: true }, role: { isRequired: true }, + partnerName: { isRequired: true }, }, actions: { new: {