-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(account): add account deletion action, create delete account but…
…ton and form components, fix API limit bug
- Loading branch information
Showing
16 changed files
with
360 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- CreateTable | ||
CREATE TABLE "UserApiLimit" ( | ||
"id" TEXT NOT NULL, | ||
"userId" TEXT NOT NULL, | ||
"count" INTEGER NOT NULL DEFAULT 0, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "UserApiLimit_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "UserApiLimit_userId_key" ON "UserApiLimit"("userId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UserApiLimit" ADD CONSTRAINT "UserApiLimit_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use server"; | ||
|
||
import { getUserById } from "@/data/user"; | ||
import { currentUser } from "@/lib/auth"; | ||
import { db } from "@/lib/db"; | ||
|
||
export const deleteAccount = async () => { | ||
try { | ||
const user = await currentUser(); | ||
if (!user || !user.id) { | ||
throw new Error("Unauthorized: User not authenticated."); | ||
} | ||
|
||
const dbUser = await getUserById(user.id); | ||
if (!dbUser) { | ||
throw new Error("Unauthorized: User not found in the database."); | ||
} | ||
|
||
await db.user.delete({ | ||
where: { id: dbUser.id }, | ||
}); | ||
|
||
const getResponse = await fetch( | ||
`${process.env.WORKER_BASE_URL}?deleteAllUserNotes=${dbUser.email}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"X-Custom-Auth-Key": `${process.env.SECURITY_KEY}`, | ||
}, | ||
} | ||
); | ||
|
||
const data = await getResponse.text(); | ||
console.log(data); | ||
|
||
return { success: "Your account and data has been removed from Clack." }; | ||
} catch (e: any) { | ||
return { error: `There was a problem deleting your account ${e.message} ` }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"use client"; | ||
|
||
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog"; | ||
import { DeleteAccountForm } from "./DeleteAccountForm"; | ||
|
||
interface LoginButtonProps { | ||
children: React.ReactNode; | ||
mode?: "modal" | "redirect"; | ||
asChild?: boolean; | ||
} | ||
|
||
export const DeleteAccountButton = ({ children, asChild }: LoginButtonProps) => { | ||
return ( | ||
<Dialog> | ||
<DialogTrigger | ||
className="inline-flex border-2 border-red-400 rounded-lg px-3 items-center justify-center whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 border-input bg-background hover:bg-accent hover:text-accent-foreground" | ||
asChild={asChild} | ||
> | ||
{children} | ||
</DialogTrigger> | ||
<DialogContent className="p-0 w-auto bg-transparent border-none"> | ||
<DeleteAccountForm /> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.