#CORS issue for /customers when draft-order in admin
6 messages · Page 1 of 1 (latest)
add STORE_CORS to middleware.ts in server/api ?
also what is the exact error so everyone can help better
Yes i added my STORE_CORS and ADMIN_CORS, it's working for all others cases.
The request sent by the admin modal doesn't contain the appropriate request headers (no cookies, etc)
it's was working (at least its working in my production setup), i just updated to :
"@medusajs/medusa": "^1.20.4",
"@medusajs/admin": "^7.1.12",
Can someone confirm me that draft order creation is still working in medusa 1.20.4 ?
this is my api/middlewares.ts file:
import ....
const registerLoggedInUser = async (
req: MedusaRequest,
res: MedusaResponse,
next: MedusaNextFunction
) => {
let loggedInUser: User | null = null
if (req.user && req.user.userId) {
const userService =
req.scope.resolve("userService") as UserService;
loggedInUser = await userService.retrieve(req.user.userId);
} else if (req.session.user_id) {
const userService =
req.scope.resolve("userService") as UserService;
loggedInUser = await userService.retrieve(req.session.user_id)
}
req.scope.register({
loggedInUser: {
resolve: () => loggedInUser,
},
})
next()
}
const adminCors = () => {
const {configModule} = getConfigFile<ConfigModule>('/app/medusa', "medusa-config")
const { projectConfig } = configModule;
return {
origin: projectConfig.admin_cors.split(","),
credentials: true,
}
}
const storeCors = () => {
const {configModule} = getConfigFile<ConfigModule>('/app/medusa', "medusa-config")
const { projectConfig } = configModule
return {
origin: projectConfig.store_cors.split(","),
credentials: true,
}
}
export const config: MiddlewaresConfig = {
routes: [
...
{
method: ["GET", "POST", "PUT"],
matcher: /\/admin\/[^(auth)].*/,
middlewares: [registerLoggedInUser,cors(adminCors())],
},
{
method: ["GET", "POST"],
matcher: "/store/*",
middlewares: [registerLoggedInUser,cors(storeCors())],
},
],
}