-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59945d7
commit 0a225e4
Showing
5 changed files
with
107 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use server'; | ||
|
||
import { env } from '@/config/env'; | ||
import { siteConfig } from '@/config/site'; | ||
import { fileStorage } from '@/infra'; | ||
import { auth } from '@/lib/auth'; | ||
import { authAction } from '@/lib/safe-action'; | ||
import { findManyByUserId as findManyAssetsByUserId } from '@/models/asset'; | ||
import { deleteOne as deleteOneUser } from '@/models/user'; | ||
import { cookies } from 'next/headers'; | ||
import { redirect } from 'next/navigation'; | ||
import { z } from 'zod'; | ||
|
||
const schema = z.object({}); | ||
|
||
export const deleteAccount = authAction(schema, async ({}, { user }) => { | ||
// Don't need to invalidate the session, since the session table has a | ||
// cascade delete on the user id. This will automatically delete the | ||
// session when the user is deleted. | ||
const sessionCookie = auth.createBlankSessionCookie(); | ||
cookies().set( | ||
sessionCookie.name, | ||
sessionCookie.value, | ||
sessionCookie.attributes, | ||
); | ||
const assets = await findManyAssetsByUserId(user.id); | ||
await Promise.all([ | ||
fileStorage.removeObjects( | ||
env.S3_BUCKET_NAME, | ||
assets.map((asset) => asset.name), | ||
), | ||
deleteOneUser(user.id), | ||
]); | ||
return redirect(siteConfig.paths.auth.signIn); | ||
}); |
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