import { getLoggedInUser } from "@/lib/appwrite";
import { redirect } from "next/navigation";
import { ID } from "node-appwrite";
import { createAdminClient } from "@/lib/appwrite";
import { cookies } from "next/headers";
async function signUpWithEmail(formData: any) {
"use server";
const email = formData.get("email");
const password = formData.get("password");
const name = email.split("@")[0];
const { account } = await createAdminClient();
await account.create(ID.unique(), email, password, name);
const session = await account.createEmailPasswordSession(email, password);
cookies().set("my-custom-session", session.secret, {
path: "/",
httpOnly: true,
sameSite: "strict",
secure: true,
});
redirect("/create");
}
export default async function Register() {
const user = await getLoggedInUser();
if (user) redirect("/create");
return (
<form
action={signUpWithEmail}
className=""
>
<input
id="email"
name="email"
placeholder="Email"
type="email"
className=""
/>
<input
id="password"
name="password"
placeholder="Password"
minLength={8}
type="password"
className=""
/>
<button
className=""
type="submit"
>
Get Started
</button>
</form>
);
}