added registration-check for old accounts
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { prisma, Prisma } from "@repo/db";
|
import { prisma, Prisma } from "@repo/db";
|
||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
|
import OLD_USER from "../../api/auth/[...nextauth]/var.User.json";
|
||||||
|
import { OldUser } from "../../../types/oldUser";
|
||||||
|
|
||||||
export const register = async ({ password, ...user }: Omit<Prisma.UserCreateInput, "publicId">) => {
|
export const register = async ({ password, ...user }: Omit<Prisma.UserCreateInput, "publicId">) => {
|
||||||
const hashedPassword = await bcrypt.hash(password, 12);
|
const hashedPassword = await bcrypt.hash(password, 12);
|
||||||
@@ -26,12 +28,22 @@ export const register = async ({ password, ...user }: Omit<Prisma.UserCreateInpu
|
|||||||
id: true,
|
id: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const existingOldUser = (OLD_USER as OldUser[]).find((u) => u.email === user.email);
|
||||||
|
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
return {
|
return {
|
||||||
error: "Ein Nutzer mit dieser E-Mail-Adresse existiert bereits.",
|
error: "Ein Nutzer mit dieser E-Mail-Adresse existiert bereits.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (existingOldUser) {
|
||||||
|
return {
|
||||||
|
error:
|
||||||
|
"Diese Email existriert bereits in der alten Version von VAR. Bitte melde dich an oder ändere dein Passwort.",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const newUser = prisma.user.create({
|
const newUser = prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
...user,
|
...user,
|
||||||
|
|||||||
Reference in New Issue
Block a user