mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 12:36:57 +00:00
Account deletion
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import { ObjectId } from "mongodb";
|
||||
import { z } from "zod";
|
||||
|
||||
import { adapter, auth } from "@/auth";
|
||||
import { collections, dbConnect } from "@/server/mongodb";
|
||||
import { errorLog } from "@/utils/logger";
|
||||
|
||||
import { action } from "./safeAction";
|
||||
|
||||
export const deleteAccount = action(z.void(), async () => {
|
||||
try {
|
||||
await dbConnect();
|
||||
|
||||
const user = await auth();
|
||||
if (!user?.user) {
|
||||
throw new Error("You must be logged in to delete your account");
|
||||
}
|
||||
|
||||
await collections.zones!.deleteMany({
|
||||
userId: new ObjectId(user.user!.id!),
|
||||
});
|
||||
|
||||
await adapter.deleteUser!(user.user!.id!);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
errorLog(error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
@@ -4,3 +4,8 @@ export type UserModel = {
|
||||
email: string;
|
||||
emailVerified?: Date;
|
||||
};
|
||||
|
||||
export type VerificationModel = {
|
||||
identifier: string;
|
||||
expires: Date;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import mongoDB, { MongoClient } from "mongodb";
|
||||
|
||||
import { TournamentModel } from "@/server/models/tournamentModel";
|
||||
import { UserModel } from "@/server/models/userModel";
|
||||
import { UserModel, VerificationModel } from "@/server/models/userModel";
|
||||
import { ZoneModel } from "@/server/models/zoneModel";
|
||||
|
||||
import { ClubModel } from "./models/clubModel";
|
||||
@@ -11,6 +11,7 @@ export const collections: {
|
||||
clubs?: mongoDB.Collection<ClubModel>;
|
||||
users?: mongoDB.Collection<UserModel>;
|
||||
zones?: mongoDB.Collection<ZoneModel>;
|
||||
userVerificationTokens?: mongoDB.Collection<VerificationModel>;
|
||||
} = {};
|
||||
|
||||
if (!process.env.MONGODB_URI) {
|
||||
@@ -52,6 +53,9 @@ export async function dbConnect() {
|
||||
|
||||
const userData: mongoDB.Db = p.db("userData");
|
||||
collections.users = userData.collection("userData");
|
||||
collections.userVerificationTokens = userData.collection(
|
||||
"userVerificationTokens",
|
||||
);
|
||||
collections.zones = userData.collection("zones");
|
||||
|
||||
const tournamentData: mongoDB.Db = p.db("tournamentsFranceDB");
|
||||
|
||||
Reference in New Issue
Block a user