Next.js Discord

Discord Forum

server actions

Unanswered
Havana posted this in #help-forum
Open in Discord
HavanaOP
How to use server actions over here . I am getting this error .
code :
"use server";

import authService from "@/app/_appwrite/auth";
import { redirect } from "next/navigation";

export async function createUserAction({
  email,
  password,
}: {
  email: string;
  password: string;
}) {
  try {
    const userSignUp = await authService.createAccount({
      email,
      password,
    });

    const result = JSON.parse(JSON.stringify(userSignUp));
    if (result) {
      redirect("/");
    } else {
      return { success: false };
    }
  } catch (err) {
    console.error(err);
    return { success: false, error: err };
  }
}

appwrite method
async createAccount({
    email,
    password,
  }: {
    email: string;
    password: string;
  }) {
    try {
      let userAccount = await this.account.create(ID.unique(), email, password);
      if (userAccount) {
        return userAccount;
      } else {
        return null;
      }
    } catch (error) {
      throw error;
    }
  }

<form
          action={form.handleSubmit(createUserAction)}
          className="space-y-8"
        >

19 Replies

Dunker
what about
action={createUserAction(email, password}
HavanaOP
Error: e._formData.get is not a function
Im not entirely sure but i dont think you can take in objects like that
Actions provided to <form> should be taking a Form Data as argument. You can then parse/validate that if you want to.
HavanaOP
@Clown for this also i am getting the error
lol does ("use server") work... i didn't know that
@Havana <@678259999201427466> for this also i am getting the error
HavanaOP
"use server";
is only changed for that img part
Which node version are you using?
@riský lol does ("use server") work... i didn't know that
HavanaOP
for just showing below func
i put the user server bellow and the prettier did that parenthesis
@Clown Which node version are you using?
HavanaOP
@Clown Which node version are you using?
This and try clear your node_modules and .next folder
@Clown This and try clear your node_modules and .next folder
HavanaOP
sure , will try that
removing the node_modules and .next dir
after installing new dependencies and running the server again the same err
I dont even know why you are getting that tho :/.
You arent using the get function
Maybe its due to another package?
HavanaOP
could be that