mirror of
https://github.com/cfngc4594/monaco-editor-lsp-next.git
synced 2025-05-19 07:56:34 +00:00
27 lines
731 B
TypeScript
27 lines
731 B
TypeScript
|
"use server";
|
||
|
|
||
|
import bcrypt from "bcrypt";
|
||
|
import prisma from "@/lib/prisma";
|
||
|
import { signIn } from "@/lib/auth";
|
||
|
import { authSchema } from "@/lib/zod";
|
||
|
import { redirect } from "next/navigation";
|
||
|
|
||
|
export async function signInWithCredentials(formData: { email: string; password: string }) {
|
||
|
await signIn("credentials", formData);
|
||
|
}
|
||
|
|
||
|
export async function signUpWithCredentials(formData: { email: string; password: string }) {
|
||
|
const validatedData = await authSchema.parseAsync(formData);
|
||
|
const saltRounds = 10;
|
||
|
const pwHash = await bcrypt.hash(validatedData.password, saltRounds);
|
||
|
|
||
|
await prisma.user.create({
|
||
|
data: {
|
||
|
email: validatedData.email,
|
||
|
password: pwHash,
|
||
|
},
|
||
|
});
|
||
|
|
||
|
redirect("/sign-in");
|
||
|
}
|