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

Handle login request form data #783

Open
asacarter opened this issue Jul 13, 2024 · 2 comments
Open

Handle login request form data #783

asacarter opened this issue Jul 13, 2024 · 2 comments

Comments

@asacarter
Copy link

As is with the authentication, it seems everything is handled by the library internally and there is no way to handle the form data from login form requests.

export const action = async ({ request }) => {
  const formData = await request.formData();
  const errors = loginErrorMessage(await login(request));
  ...

The request body can only be consumed once so trying to request the formData will fail.

If the user enters an invalid url, the user is taken to a full page outside of the app and shows a 500 error which is a very poor experience.

Screenshot 2024-07-13 at 21 59 00

A better experience would be to check that a URL exists and display an error if not.

However my preferred approach is for the app template to be more open and customisable.

I'd really like to use the official template instead of my own but there are still so many issues like this that still make it unusable.

This is how I check a url exists in my template, along with disabled and loading props on the submit button.

export async function checkWebsiteExists(url) {
  // Check the url begins with http:// or https://
  if (!url.startsWith('https://') || !url.startsWith('http://')) {
    url = 'https://' + url;
  }

  try {
    const response = await fetch(url, { method: 'HEAD' });
    if (response.ok) {
      return true;
    } else {
      return false;
    }
  } catch (error) {
    return false;
  }
}
@matteodepalo
Copy link
Contributor

Hi @asacarter thank you for your feedback, I'll put this issue in our backlog so our team can take a look.

@sle-c
Copy link
Contributor

sle-c commented Dec 5, 2024

Hey @asacarter , there are 2 issues I see from this thread. I'm trying to understand the problem better.

Error flow

I tried to navigate to an invalid URL in the app. It shows a 404 for the app with the top menubar and sidebar.

Image

This is pretty standard for apps on Shopify so I'm not too sure how you'd like to change it.

Request body not returned

The request body can only be consumed once so trying to request the formData will fail.

That is true, we read the request body using request.formData() inside the login function. This is a decision from Remix.

If you need the .formData() but still want to use the template . You can clone the request as follow

const cloned = request.clone();
const formData = await cloned.formData();
const errors = loginErrorMessage(await login(request));

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

3 participants