mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-07-13 15:43:17 +00:00
N-FIN-79: refactor account data reset
This commit is contained in:
parent
98f29a8366
commit
f378e2a045
4 changed files with 54 additions and 62 deletions
|
@ -1,52 +0,0 @@
|
|||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_SIGN_IN, URL_SIGN_OUT } from '@/lib/constants';
|
||||
import prisma from '@/prisma';
|
||||
import { getSession } from '@auth0/nextjs-auth0';
|
||||
|
||||
export default async function accountDelete(): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: 'You aren\'t signed in.',
|
||||
redirect: URL_SIGN_IN,
|
||||
};
|
||||
}
|
||||
const user = session.user;
|
||||
|
||||
await prisma.payment.deleteMany({
|
||||
where: {
|
||||
userId: user.sub,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.entity.deleteMany({
|
||||
where: {
|
||||
userId: user.sub,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.category.deleteMany({
|
||||
where: {
|
||||
userId: user.sub,
|
||||
},
|
||||
});
|
||||
|
||||
let requestOptions = {
|
||||
method: 'DELETE',
|
||||
redirect: 'follow',
|
||||
} as RequestInit;
|
||||
|
||||
fetch(`https://login.auth0.com/api/v2/users/${user.sub}`, requestOptions)
|
||||
.then(response => response.text())
|
||||
.then(result => console.log(result))
|
||||
.catch(error => console.log('error', error));
|
||||
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'Your account was removed.',
|
||||
redirect: URL_SIGN_OUT,
|
||||
};
|
||||
}
|
40
src/lib/actions/clearAccountData.ts
Normal file
40
src/lib/actions/clearAccountData.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { ActionResponse } from '@/lib/types/actionResponse';
|
||||
import { URL_SIGN_IN } from '@/lib/constants';
|
||||
import prisma from '@/prisma';
|
||||
import { getSession } from '@auth0/nextjs-auth0';
|
||||
|
||||
export default async function clearAccountData(): Promise<ActionResponse> {
|
||||
'use server';
|
||||
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: 'You aren\'t signed in.',
|
||||
redirect: URL_SIGN_IN,
|
||||
};
|
||||
}
|
||||
|
||||
await prisma.payment.deleteMany({
|
||||
where: {
|
||||
userId: session.user.sub,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.entity.deleteMany({
|
||||
where: {
|
||||
userId: session.user.sub,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.category.deleteMany({
|
||||
where: {
|
||||
userId: session.user.sub,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'Your account data was cleared.',
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue