Back

Hey, i am trying to create a user

  • 0
  • Auth
silas__
9 Jul, 2024, 15:42

because i am following a tutorial, where i am pretty sure i have done everything correct

TL;DR
Developers encountering an invalid URL error when trying to create a new user. They're using Appwrite and need to ensure their .env file is set up correctly with the correct string-based endpoint. The function for creating a user should use account.create instead of users.create for their purpose. Additionally, they should check if the email being used already exists in Appwrite to prevent creating duplicate accounts. The issue could also be related to the formatting or setup of the .env file.
Kenny
9 Jul, 2024, 15:42

what tutorial

silas__
9 Jul, 2024, 15:43

the appwrite section where i am stuck at the end is at hour 1

Kenny
9 Jul, 2024, 15:46

add a log in your catch

TypeScript
export const createUser = async (user: CreateUserParams) => {
  try {
    // Create new user -> https://appwrite.io/docs/references/1.5.x/server-nodejs/users#create
    const newuser = await users.create(
      ID.unique(),
      user.email,
      user.phone,
      undefined,
      user.name
    );

    return parseStringify(newuser);
  } catch (error: any) {
    // Check existing user
    if (error && error?.code === 409) {
      const existingUser = await users.list([
        Query.equal("email", [user.email]),
      ]);

      return existingUser.users[0];
    }
    console.error("An error occurred while creating a new user:", error);
  }
};
Kenny
9 Jul, 2024, 15:46

do you get that error?

Kenny
9 Jul, 2024, 15:47

is your env file setup correctly?

silas__
9 Jul, 2024, 15:47
silas__
9 Jul, 2024, 15:48

yes my env file shoud be correct

silas__
9 Jul, 2024, 15:48

i went over it again before reaching for support

silas__
9 Jul, 2024, 15:49

An error occurred while creating a new user: TypeError: Failed to construct 'URL': Invalid URL at Users.create (users.mjs:77:17) at createUser (patient.actions.ts:8:33) at onSubmit (PatientForm.tsx:51:36) at eval (index.esm.mjs:2256:23)

silas__
9 Jul, 2024, 15:49

thats the whole error

Kenny
9 Jul, 2024, 15:49

Sure, looks like something is not formatted correctly. Maybe the email?

silas__
9 Jul, 2024, 15:50

it should all be string

Kenny
9 Jul, 2024, 15:50

What do you have in your .env for ENDPOINT

silas__
9 Jul, 2024, 15:50
silas__
9 Jul, 2024, 15:51
silas__
9 Jul, 2024, 15:51

thats my endpoint

Kenny
9 Jul, 2024, 15:52

so you've got NEXT_PUBLIC_ENDPOINT=https://cloud.appwrite.io/v1?

silas__
9 Jul, 2024, 15:53

correct

silas__
9 Jul, 2024, 15:53

this is my .env.public

silas__
9 Jul, 2024, 15:53

i only do this for training if you wonder

Kenny
9 Jul, 2024, 15:56

change it to just .env

Kenny
9 Jul, 2024, 15:57

I thought nextjs only support .env, .env.local, .env.development, and .env.production out of the box.

silas__
9 Jul, 2024, 15:59

that didnt change anything i thinj

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more