Shopify Remix App: Issue with shopify.authenticate.admin on Random Pages

Topic summary

Developers are experiencing an intermittent authentication error in Shopify Remix apps where shopify.authenticate.admin() randomly fails about 5% of the time, throwing a 500 error that suggests the method is being called from the login path instead of using shopify.login().

Key characteristics:

  • Error occurs randomly across different pages, not tied to specific routes
  • Simply refreshing the browser immediately resolves the issue
  • Original poster suspects expired/invalid admin tokens may be the cause

Solution identified:
One developer found that the issue stems from not properly passing URL search parameters during redirects. The fix involves preserving query parameters (particularly the shop parameter) when redirecting:

throw redirect(`/app?${url.searchParams.toString()}`);

Multiple users confirmed experiencing this same problem, with the solution appearing to address the root cause of the authentication failure.

Summarized with AI on October 26. AI used: claude-sonnet-4-5-20250929.

Problem Description

I am developing a Shopify Remix App, and I’m encountering an intermittent issue with the shopify.authenticate.admin() method. Occasionally, around 5% of the time, the following error occurs:

{
status: 500,
statusText: '',
internal: false,
data: "Detected call to shopify.authenticate.admin() from configured login path ('/auth/login'), please make sure to call shopify.login() from that route instead."
}

This error randomly occurs on different pages of my app where shopify.authenticate.admin() is called. It is not tied to any specific page or action. The strange part is that simply refreshing the browser resolves the issue immediately, and the app works as expected.


Hypothesis

I suspect that the issue might be related to the admin token being expired or invalid at the time the authenticate.admin function is called. This could explain why refreshing the browser resolves the problem, as it likely triggers a new session or re-validation process.

How can this issue be resolved, or are there any directions I can explore to address it?

4 Likes

Hi @ericlee996 , I am experiencing the same problem. Did you find the solution for this?

2 Likes

I have the same problem, has anyone earn a solution yet?

I was also having this issue. Found the solution: you need to pass the request search params to the page you’re redirecting to:

export const loader = async ({ request }: LoaderFunctionArgs) => {
  const url = new URL(request.url);
  if (url.searchParams.get("shop")) {
    throw redirect(`/app?${url.searchParams.toString()}`);
  }
}