DeFacedFaceOriginal post
Rank 1: Thread
So I'm attempting to re-do my signup process because I ran into issues adding to the database at the same time.
But im having issues. I read the docs and it absolutely cannot see what im doing wrong. It creates a account just fine on appwrite but wont redirect me to my dashboard.
sign up form code
import {
getLoggedInUser,
createUserClient,
createSessionClient,
} from "@/lib/server/appwrite";
import { redirect } from "next/navigation";
import { ID } from "appwrite";
import { cookies } from "next/headers";
import Link from "next/link";
export default async function RegisterPage() {
const user = await getLoggedInUser();
if (user) redirect("/dashboard");
async function handleRegister(formData) {
"use server";
const organization = formData.get("organization");
const email = formData.get("email");
const password = formData.get("password");
const repeatPassword = formData.get("repeatPassword");
const missionStatement = formData.get("missionStatement");
const organizationWebsite = formData.get("organizationWebsite");
if (password !== repeatPassword) {
// handle this error better
console.log("Passwords do not match");
}
const { account } = await createSessionClient();
try {
await account.create(ID.unique(), email, password, organization);
const session = await account.createEmailPasswordSession(email, password);
cookies().set("my-custom-session", session.secret, {
path: "/",
httpOnly: true,
sameSite: "Strict",
secure: true,
});
redirect("/dashboard");
// const data = { organization, missionStatement, organizationWebsite };
// await saveToDatabase(data);
} catch (error) {
console.log("Registration failed: " + error.message);
}
}
return (
form code stuff
)
Summary
Developers are facing an issue where the signup process successfully creates an account on Appwrite but fails to redirect to the dashboard. The problem lies in the code not redirecting users after successful signup. To solve this, include `return` before `redirect("/dashboard");` in the handleRegister function.