Still redirected to Shopify login even after removing all account route logic?

I’m working on a custom Hydrogen + Remix storefront, and I’m running into something strange with the /account routes.

I’ve implemented my own customer login system, using the customerAccessTokenCreate mutation and storing the token in a custom session (via createCookieSessionStorage). Here’s a quick summary of the flow:

  • A custom /account/login page sends the login credentials to Shopify via GraphQL
  • If successful, I store the customerAccessToken and customerAccessTokenExpiresAt in a session cookie
  • The session is then used in other routes to protect /account pages
  • I have a useAuth() hook that reads the current auth state from the root loader

Example: My login handler

 /routes/login
const data = await storefront.mutate(CUSTOMER_ACCESS_TOKEN_CREATE_MUTATION, { ... });

session.set('customerAccessToken', data.customerAccessToken.accessToken);
session.set('customerAccessTokenExpiresAt', data.customerAccessToken.expiresAt);

return redirect('/', {
  headers: {
    'Set-Cookie': await session.commit(),
  },
});

The Issue

Even after:

  • Replacing account.tsx and account.$.tsx with blank files
  • Deleting any calls to context.customerAccount.handleAuthStatus()
  • Removing the account.authorize.tsx file entirely

I’m still being redirected to Shopify’s OAuth login page, with a URL like:

https://shopify.com/authentication/....../oauth/authorize?client_id=

This happens any time I try to visit /accounteven when those route files are essentially empty. My main goal was to use my own code the check if a user is logged in and then allow them to access their accounts page with my own auth check code. But for some reason with deleting all code in those account files, I am STILL redirected to that account/authorize route.

Is there some internal behavior (maybe in Hydrogen or remix-oxygen) that auto-forwards to Shopify login under certain conditions?

Or am I missing something else that might still be triggering the redirect?

Are there any remaining references to customerAccount?

Oh, you are correct! In my account.tsx we had

const {data, errors} = await context.customerAccount.query(
    CUSTOMER_DETAILS_QUERY,
);

Which was causing it. I was able to adjust the query to use storefront with:

export async function loader({context}: LoaderFunctionArgs) {
  const customerAccessToken = await context.session.get('customerAccessToken');
  if (!customerAccessToken) {
    throw new Error('Missing customer token');
  }
  
  try {
    const response = await context.storefront.query(
      CUSTOMER_DETAILS_QUERY,
      {
        variables: {
          customerAccessToken,
        },
      }
    );
    
    // Log the full response for debugging
    console.log('Full response:', JSON.stringify(response, null, 2));
    
    // Check if response has the customer property directly (not inside data)
    if (!response.customer) {
      console.error('No customer in response:', response);
      throw new Error('Customer not found in response');
    }
    
    return remixData(
      {customer: response.customer}
    );
  } catch (error) {
    console.error('Error in loader:', error);
    throw error;
  }
}

Thank you for the help!

1 Like