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

authenticate.public.checkout CORS failed to respond #492

Closed
liam997 opened this issue Nov 15, 2023 · 3 comments
Closed

authenticate.public.checkout CORS failed to respond #492

liam997 opened this issue Nov 15, 2023 · 3 comments

Comments

@liam997
Copy link

liam997 commented Nov 15, 2023

Issue summary

Checkout UI extension validate failed.

  • "@shopify/shopify-app-remix": "^2.0.0",
  • Node version: 18.18
  • Operating system: Ubuntu 22.04.3 LTS
// Paste any relevant logs here
import { json } from "@remix-run/node";
import { authenticate } from "../shopify.server";

export const loader = async ({ request }) => {
  const { sessionToken, cors } = await authenticate.public.checkout(
    request
  );
    return cors(json({
        point: 500,
        covert_rate: 10,
    }));
};

Error log


13:50:36 │ remix      │ OPTIONS /checkout-api/get-point 204 - - 12.669 ms
13:50:36 │ remix      │ [shopify-app/INFO] Authenticating checkout request
13:50:36 │ remix      │ GET /checkout-api/get-point 401 - - 3.017 ms

Expected behavior

It should return 200 and JSON like in object

Actual behavior

I get a 204 OPTIONS and 401 GET response

Steps to reproduce the problem

  1. Install remix app
  2. Create an extension allow network access.
  3. Create an API with code for validate in the docs
  4. Add fetch route to API in checkout UI extension
  5. Open developer preview for test
@liam997
Copy link
Author

liam997 commented Nov 16, 2023

After a while of checking.

It worth metion there need to use sessionToken from useAPI() to verify

@liam997 liam997 closed this as completed Nov 16, 2023
@mrkaluzny
Copy link

mrkaluzny commented Aug 8, 2024

@liam997 I get this same error with provided sessionToken. The server gets Options request and returns 401 response, CORS seems not to do anything that is authethicated through public.

I also tried remix/utils

// routes/api.js
export const loader = async ({ request }) => {
  const { cors, sessionToken } = await authenticate.public.checkout(request);
  return cors(json([]));
};

Request

const token = await sessionToken.get();
const res = await fetch(`${APP_URL}/api/endpoint`, {
           method: "GET",
           headers: {
             Authorization: `Bearer ${token}`,
             "Content-Type": "application/json",
           },
       },
);

const data = await res.json();

@mrkaluzny
Copy link

@liam997 Huh it actually works without changes when deployed :)

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

No branches or pull requests

2 participants