Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS error in specific admin routes #6809

Closed
kevinrobert3 opened this issue Mar 24, 2024 · 1 comment
Closed

CORS error in specific admin routes #6809

kevinrobert3 opened this issue Mar 24, 2024 · 1 comment

Comments

@kevinrobert3
Copy link

kevinrobert3 commented Mar 24, 2024

Bug report

Describe the bug

Admin routes like /customers, /products, /orders have a cors error

System information

Medusa version (including plugins):
Node.js version: v20.11.1
Database: Postgres
Operating system: MacOS
Browser (if relevant): Chrome

Steps to reproduce the behavior

  1. Create a sample frontend App running on any port
  2. Make sure you have added the CORS allowed domains e.g localhost:3000/your port to your medusa config file
  3. Do a fetch call using any of the mentioned api routes e.gadmin/products
  4. You will get cors error in your browser
  5. Repeat with non-affected routes like admin/auth/token, admin/users , admin/users/{id} and the api call will succeed

Expected behavior

A 200 response from server with all routes

Screenshots

Screen.Recording.2024-03-25.at.03.07.27.1.1.mov

Code snippets

The below code will work

await fetch(
            `${process.env.NEXT_PUBLIC_MEDUSA_URL}/admin/users/usr_01HSDSC3DNQ0KG6DQPCESWH0AJ`,
            {
              method: "POST",
              headers: {
                "Content-Type": "application/json",
                Authorization:
                  "Bearer eyJhbGciOiJIUzI1NiIsInR5",
              },

              body: JSON.stringify({
                first_name: "Medusa",
              }),
            }
          );

The below will have a cors error

await fetch(
            `${process.env.NEXT_PUBLIC_MEDUSA_URL}/admin/products`,
            {
              method: "POST",
              headers: {
                "Content-Type": "application/json",
                Authorization:
                  "Bearer eyJhbGciOiJIUzI1NiIsInR5",
              },

              body: JSON.stringify({
                title: "Medusa",
              }),
            }
          );

Additional context

Had a hunch that this could be an issue affecting the admin routes that we have extended entities and services for, like products, customers, orders but api routes that do not have extended entities and services like sales_channels and customer_groups also have the cors error .ie /admin/sales-channels like that.

@sradevski
Copy link
Member

@kevinrobert3 are you getting the same issue with our admin panel as well? Can you please try with a newly created project and see if you are having issues? I'll close the ticket as it is unlikely a bug, but a misconfiguration on your side, let me know if the issue persists, or reach out on Discord for more help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants