adrianhajdin / healthcare

Build a healthcare platform that streamlines patient registration, appointment scheduling, and medical records, and learn to implement complex forms and SMS notifications.
https://jsmastery.pro
1.81k stars 432 forks source link

TypeError: Failed to construct 'URL': Invalid URL #17

Closed pythonnelson closed 2 months ago

pythonnelson commented 2 months ago

async function onSubmit(data: z.infer) { setIsLoading(true);

try {
  console.log("Form Data Submitted:", data);
  const userData = {
    name: data.name,
    email: data.email,
    phone: data.phone,
  };
  const user = await createUser(userData);
  console.log("User Created:", user); // Log user data
  if (user) {
    router.push(`/visitors/${user.$id}/register`);
  }
} catch (error) {
  console.log("Submission Error:", error); // Log any submission errors
} finally {
  setIsLoading(false);
}

}

When i try to submit the welcome form, i get undefined, the code is not reaching at the level to create the user. Hence i got an undefined in the log.

And also i got an invalid url, but when i log the environment variables, i noticed that they are being read in the project.

Further debugging, when i provide the environment variables (API_KEY, PROJECT_ID and ENDPOINT) directly in the filename.actions.ts file, the user i created but the the id of the user is undefined.

janleven01 commented 2 months ago

Try putting 'use server' on patient.actions.ts file. It's not emphasize in the vid

pythonnelson commented 2 months ago

Try putting 'use server' on patient.actions.ts file. It's not emphasize in the vid

Thanks mate, it worked now by creating the user .... but still having the undefined in the patientForm at:

const user = await createUser(userData)

ssaintx commented 2 months ago

Try putting 'use server' on patient.actions.ts file. It's not emphasize in the vid

Thanks mate, it worked now by creating the user .... but still having the undefined in the patientForm at:

const user = await createUser(userData)

Try to console log the the data you receiving. Check for spelling error. And mostly check for argument types you receving. You can get some error caused by type error

ghost commented 2 months ago

I think issue is in appwrite file for some reason process.env is not deconstructing the values correctly and you have to set endpoints manually. client.setEndpoint("https://cloud.appwrite.io/v1").setProject("here.setProject(%22here) project id").setKey("here api key.");