#how to set the payload cookie/token on payload.login in 3.0 with Next JS and server actions
1 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
how to set the payload cookie/token on payload.login in 3.0 with Next JS and server actions
Hey @wispy ingot have you got any solution for this? I'm finf the same
@livid flame can you answer this?
this is my signin form action
export async function signIn(_: any, formData: FormData): Promise<ActionResult> {
"use server";
const email = formData.get("email") as string;
const password = formData.get("password") as string;
const payload = await getFullPayload()
try {
const user = await payload.login({
collection: 'users',
data: {
email,
password
},
})
cookies().set({
name: "payload-token",
value: user.token,
path: "/",
expires: new Date(user.exp * 1000),
});
} catch (e) {
if (e.name === "ValidationError") {
return {
error: "validation_error",
};
}
if (e.name === "AuthenticationError") {
return {
error: "authentication_error",
};
}
if (e.name === "LockedAuth") {
return {
error: "locked",
};
}
return {
error: "unknown_error",
};
}
return redirect("/");
}
should do what you need