Skip to content

Commit

Permalink
use common API_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Oct 18, 2024
1 parent 02d38f3 commit a6592ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions admin/providers/auth.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions admin/resources/users/user.actions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand Down

0 comments on commit a6592ed

Please sign in to comment.