
when i signup user gets created to auth and user added as document in user collection (saved to db) but it is not redirected to / (home) route
async function handleSignup(values: z.infer<typeof formSchema>) {
    try {
      
    
    const newUser =await createUserAccount(values);
    if(newUser){
      return toast({
        title: 'Sign up failed! Please try again.'
      })
    }
    const session = await signInAccount({
      email:values.email,
    password:values.password
    })
    if(!session) {
       toast({title:"sign in failed, Please try again."})
       navigate("/sign-in");
        
       return;
    }
    const isLoggedIn=await checkAuthUser();
    if(isLoggedIn){
      form.reset()
      navigate('/')
    }else{
       toast({title:"Sign up failed! Please try again"})
       return;
    }
  } catch (error) {
      console.log(error);
      
  }
my handleSignup function

I think the issue is that you're not routing after createUserAccount?

but i have to navigate to / only when it is signedin

Ok. Let me do a rewrite

i followed a tutorial and did almost exactly as he did but still getting messed up

What's exactly createUserAccount(values);?

This is JS, right?

Ts

Okay. What's the code for such function?

I mean createUserAccount(values);

values: { username: string; email: string; name: string; password: string; }

    try {
      const newAccount = await account.create(
        ID.unique(),
        user.email,
        user.password,
        user.name
      );
  
      if (!newAccount) throw Error;
  
      const avatarUrl = avatars.getInitials(user.name);
  
      const newUser = await saveUserToDB({
        accountId: newAccount.$id,
        name: newAccount.name,
        email: newAccount.email,
        username: user.username,
        imageUrl: avatarUrl,
      });
  
      return newUser;
    } catch (error) {
      console.log(error);
      return error;
    }
  }
  
  export async function saveUserToDB(user: {
    accountId: string;
    email: string;
    name: string;
    imageUrl: URL;
    username?: string;
  }) {
    try {
      const newUser = await databases.createDocument(
        appwriteConfig.databaseId,
        appwriteConfig.userCollectionId,
        ID.unique(),
        user
      );
        console.log(newUser);
        
      return newUser;
    } catch (error) {
      console.log(error);
    }
  }```

Ok. That looks fine for me

I think the first part should look like this?
    const newUser = await createUserAccount(values);
    if(newUser){
  // Redirect the user here since it has been logged in:
    navigate('/')
    } else {
//Show errors here
}
Recommended threads
- How to ByPass the Hostname restriction f...Hello, Im hosting my React application in a stateless server environment, where the IP of the client keeps changing for the server. How do I bypass the hostname... 
- Email templates partially broken in non-...Good afternoon! Non-english locales are missing some variables introduced in recent releases. That makes the sent emails look bad. The issue has been raised a... 
- Query.contains not supported on Cloud?I try to filter a row which contain a string inside a string array column, however I get the following error: ``` {"name":"AppwriteException","code":400,"type"... 
