"use server";
import { authUserActionClient } from "../safe-action";
import { completeUserSchema } from "@/lib/zod/schema/users";
import { auth } from "@/lib/better-auth/auth";
import { prisma } from "@/lib/prisma";
export const updateUserAccountAction = authUserActionClient
.schema(completeUserSchema)
.action(async ({ ctx, parsedInput }) => {
const { password, name } = parsedInput;
const id = ctx.user.id;
const authCtx = await auth.$context;
const hash = await authCtx.password.hash(password);
try {
await authCtx.internalAdapter.updatePassword(id, hash);
} catch (error) {
console.error(error);
throw new Error("Failed to update password");
}
await prisma.user.update({
where: { id },
data: {
name,
},
});
return { ok: true };
});
"use server";
import { authUserActionClient } from "../safe-action";
import { completeUserSchema } from "@/lib/zod/schema/users";
import { auth } from "@/lib/better-auth/auth";
import { prisma } from "@/lib/prisma";
export const updateUserAccountAction = authUserActionClient
.schema(completeUserSchema)
.action(async ({ ctx, parsedInput }) => {
const { password, name } = parsedInput;
const id = ctx.user.id;
const authCtx = await auth.$context;
const hash = await authCtx.password.hash(password);
try {
await authCtx.internalAdapter.updatePassword(id, hash);
} catch (error) {
console.error(error);
throw new Error("Failed to update password");
}
await prisma.user.update({
where: { id },
data: {
name,
},
});
return { ok: true };
});