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

Add a /admin route that redirects to the online store admin page #989

Merged
merged 2 commits into from Jun 7, 2023

Conversation

blittle
Copy link
Contributor

@blittle blittle commented Jun 7, 2023

WHY are these changes introduced?

Add a /admin route that redirects to the Shopify admin. This redirect can be disabled by passing noAdminRedirect: true to storefrontRedirect:

storefrontRedirect({
  redirect,
  response,
  storefront,
  noAdminRedirect: true,
});

Resolves #988

WHAT is this pull request doing?

HOW to test your changes?

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

response = new Response('Not Found', {status: 404}),
} = options;

const {pathname, search} = new URL(request.url);
const redirectFrom = pathname + search;

if (pathname === '/admin' && !noAdminRedirect) {
const match = /https:\/\/([^.]+)\.myshopify\.com/g.exec(
Copy link
Contributor Author

@blittle blittle Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume here that the shop name cannot have a . in it. But if for some reason the regex doesn't match, instead it redirects to https://hydrogen-preview.myshopify.com/admin which does another redirect to https://admin.shopify.com/store/hydrogen-preview.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, it can't have a . — and yes, that's the right behaviour. Down the road, we could redirect you directly to https://admin.shopify.com/store/${storename} — but that URL isn't rolled out yet to everyone. In a couple months we can make that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize that URL isn't yet available to everyone. I'll change it to use https://hydrogen-preview.myshopify.com/admin instead.

@blittle blittle merged commit 5124d61 into 2023-04 Jun 7, 2023
10 checks passed
@blittle blittle deleted the bl-admin-redirect branch June 7, 2023 21:21
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

Successfully merging this pull request may close these issues.

/admin redirect in storefrontRedirect
2 participants