mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
fix delete account
This commit is contained in:
@@ -12,10 +12,7 @@ const eventsStackedSelectIndex = ref<number>(0);
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
if (route.query.just_logged) return location.href = '/';
|
||||||
if (route.query.just_logged) {
|
|
||||||
return location.href = '/';
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,14 +28,10 @@ async function handleOnSuccess(response: any) {
|
|||||||
|
|
||||||
console.log('LOGIN DONE - USER', loggedUser.value);
|
console.log('LOGIN DONE - USER', loggedUser.value);
|
||||||
|
|
||||||
const { refresh } = useProjectsList();
|
|
||||||
|
|
||||||
const isFirstTime = await $fetch<boolean>('/api/user/is_first_time', { headers: { 'Authorization': 'Bearer ' + token.value } })
|
const isFirstTime = await $fetch<boolean>('/api/user/is_first_time', { headers: { 'Authorization': 'Bearer ' + token.value } })
|
||||||
|
|
||||||
await refresh();
|
|
||||||
|
|
||||||
if (isFirstTime === true) {
|
if (isFirstTime === true) {
|
||||||
router.push('/project_creation');
|
router.push('/project_creation?just_logged=true');
|
||||||
} else {
|
} else {
|
||||||
router.push('/?just_logged=true');
|
router.push('/?just_logged=true');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ function getPremiumName(type: number) {
|
|||||||
<div class="w-full h-full p-8 overflow-y-auto pb-40 lg:pb-0 relative overflow-x-hidden">
|
<div class="w-full h-full p-8 overflow-y-auto pb-40 lg:pb-0 relative overflow-x-hidden">
|
||||||
|
|
||||||
<Transition name="pdrawer">
|
<Transition name="pdrawer">
|
||||||
<PricingDrawer @onCloseClick="showPricingDrawer = false" class="bg-black fixed right-0 top-0 w-full xl:w-[60vw] xl:min-w-[65rem] h-full z-[20]"
|
<PricingDrawer @onCloseClick="showPricingDrawer = false"
|
||||||
|
class="bg-black fixed right-0 top-0 w-full xl:w-[60vw] xl:min-w-[65rem] h-full z-[20]"
|
||||||
v-if=showPricingDrawer>
|
v-if=showPricingDrawer>
|
||||||
</PricingDrawer>
|
</PricingDrawer>
|
||||||
</Transition>
|
</Transition>
|
||||||
@@ -205,7 +206,6 @@ function getPremiumName(type: number) {
|
|||||||
|
|
||||||
</CardTitled>
|
</CardTitled>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ const isFirstProject = computed(() => { return projects.value?.length == 0; })
|
|||||||
|
|
||||||
import { Lit } from 'litlyx';
|
import { Lit } from 'litlyx';
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (projects.value?.length == 0) {
|
if (route.query.just_logged) return location.href = '/project_creation';
|
||||||
setPageLayout('none');
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ async function createProject() {
|
|||||||
await setActiveProject(newActiveProjectId);
|
await setActiveProject(newActiveProjectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
router.push('/');
|
router.push('/');
|
||||||
|
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
|
|||||||
@@ -35,11 +35,25 @@ async function deleteProject(projectId: string, projectName: string) {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { setToken } = useAccessToken();
|
||||||
|
|
||||||
async function onProjectClick(pid: string) {
|
async function onProjectClick(pid: string) {
|
||||||
await setActiveProject(pid)
|
await setActiveProject(pid)
|
||||||
router.push('/')
|
router.push('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteAccount() {
|
||||||
|
const sure = confirm("Are you sure you want to delete this account ?");
|
||||||
|
if (!sure) return;
|
||||||
|
await $fetch("/api/user/delete_account", {
|
||||||
|
...signHeaders(),
|
||||||
|
method: "DELETE"
|
||||||
|
})
|
||||||
|
|
||||||
|
setToken('');
|
||||||
|
location.href = "/login"
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -85,39 +99,26 @@ async function onProjectClick(pid: string) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
|
||||||
<div class="bg-blue-500/20 hover:bg-blue-500/30 p-4 w-[20rem] h-[6rem] flex items-center gap-4 rounded-xl cursor-pointer relative"
|
|
||||||
v-for="e of projects" @click="setActiveProject(e._id.toString())">
|
|
||||||
<div class="absolute right-2 top-2" v-if="project._id == e._id">
|
|
||||||
<i class="far fa-circle-check text-green-600"></i>
|
|
||||||
</div>
|
|
||||||
<div class="h-full aspect-[1/1]">
|
|
||||||
<div class="w-full h-full bg-blue-500 rounded-xl"></div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="text-text text-ellipsis line-clamp-1 font-semibold manrope text-[1.1rem]">
|
|
||||||
{{ e.name }}
|
|
||||||
</div>
|
|
||||||
<div class="text-text-sub font-normal lato text-[.9rem]">
|
|
||||||
{{ e.premium ? 'PREMIUM PLAN' : 'FREE PLAN' }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<!-- <NuxtLink v-if="(projects?.length || 0) < 3" to="/project_creation"
|
|
||||||
class="bg-blue-500/20 hover:bg-blue-500/30 p-4 w-[20rem] h-[6rem] flex items-center gap-4 rounded-xl cursor-pointer">
|
|
||||||
<div class="h-full aspect-[1/1] flex items-center justify-center">
|
|
||||||
<i class="fas fa-plus text-[2rem] text-text-sub/80"></i>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="text-text font-semibold manrope text-[1.1rem]"> Create new project</div>
|
|
||||||
<div class="text-text-sub font-normal lato text-[.9rem]"></div>
|
|
||||||
</div>
|
|
||||||
</NuxtLink> -->
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="px-10">
|
||||||
|
<CardTitled title="Danger zone" :sub="''" class="p-4 mt-8">
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="outline rounded-lg w-fit px-8 py-4 flex flex-col gap-4 outline-[1px] outline-[#541c15] bg-[#1e1412]">
|
||||||
|
<div class="poppins font-semibold"> Deleting this account will also remove its projects </div>
|
||||||
|
<div @click="deleteAccount()"
|
||||||
|
class="text-[#e95b61] poppins font-semibold cursor-pointer hover:text-black hover:bg-red-700 outline rounded-lg w-fit px-8 py-2 outline-[1px] outline-[#532b26] bg-[#291415]">
|
||||||
|
Delete account
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</CardTitled>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
||||||
|
import { EventModel } from "@schema/metrics/EventSchema";
|
||||||
|
import { VisitModel } from "@schema/metrics/VisitSchema";
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
const userData = getRequestUser(event);
|
const userData = getRequestUser(event);
|
||||||
@@ -9,7 +11,10 @@ export default defineEventHandler(async event => {
|
|||||||
const { project_id } = getQuery(event);
|
const { project_id } = getQuery(event);
|
||||||
if (!project_id) return setResponseStatus(event, 400, 'ProjectId is required');
|
if (!project_id) return setResponseStatus(event, 400, 'ProjectId is required');
|
||||||
|
|
||||||
await ProjectCountModel.updateOne({ project_id, events: 0, visits: 0 }, {}, { upsert: true });
|
const events = await EventModel.countDocuments({ project_id });
|
||||||
|
const visits = await VisitModel.countDocuments({ project_id });
|
||||||
|
|
||||||
|
await ProjectCountModel.updateOne({ project_id, events, visits }, {}, { upsert: true });
|
||||||
|
|
||||||
return { ok: true };
|
return { ok: true };
|
||||||
});
|
});
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
import { ProjectModel } from "@schema/ProjectSchema";
|
import { ProjectModel } from "@schema/ProjectSchema";
|
||||||
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
||||||
import { ProjectLimitModel } from "@schema/ProjectsLimits";
|
import { ProjectLimitModel } from "@schema/ProjectsLimits";
|
||||||
|
import { SessionModel } from "@schema/metrics/SessionSchema";
|
||||||
|
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
|
||||||
import StripeService from '~/server/services/StripeService';
|
import StripeService from '~/server/services/StripeService';
|
||||||
|
import { AiChatModel } from "@schema/ai/AiChatSchema";
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
const body = await readBody(event);
|
const body = await readBody(event);
|
||||||
|
|
||||||
const projectId = body.project_id;
|
const project_id = body.project_id;
|
||||||
|
|
||||||
const userData = getRequestUser(event);
|
const userData = getRequestUser(event);
|
||||||
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
||||||
|
|
||||||
const project = await ProjectModel.findById(projectId);
|
const project = await ProjectModel.findById(project_id);
|
||||||
if (!project) return setResponseStatus(event, 400, 'Project not exist');
|
if (!project) return setResponseStatus(event, 400, 'Project not exist');
|
||||||
|
|
||||||
const projects = await ProjectModel.countDocuments({ owner: userData.id });
|
const projects = await ProjectModel.countDocuments({ owner: userData.id });
|
||||||
@@ -22,18 +25,25 @@ export default defineEventHandler(async event => {
|
|||||||
|
|
||||||
await StripeService.deleteCustomer(project.customer_id);
|
await StripeService.deleteCustomer(project.customer_id);
|
||||||
|
|
||||||
const countDeletation = await ProjectCountModel.deleteOne({ owner: userData.id, _id: projectId });
|
const projectDeletation = await ProjectModel.deleteOne({ _id: project_id });
|
||||||
const limitdeletation = await ProjectLimitModel.deleteOne({ owner: userData.id, _id: projectId });
|
const countDeletation = await ProjectCountModel.deleteMany({ project_id });
|
||||||
const projectDeletation = await ProjectModel.deleteOne({ owner: userData.id, _id: projectId });
|
const limitdeletation = await ProjectLimitModel.deleteMany({ project_id });
|
||||||
|
const sessionsDeletation = await SessionModel.deleteMany({ project_id });
|
||||||
|
const notifiesDeletation = await LimitNotifyModel.deleteMany({ project_id });
|
||||||
|
const aiChatsDeletation = await AiChatModel.deleteMany({ project_id });
|
||||||
|
|
||||||
|
const ok = countDeletation.acknowledged && limitdeletation.acknowledged &&
|
||||||
|
projectDeletation.acknowledged && sessionsDeletation.acknowledged && notifiesDeletation.acknowledged && aiChatsDeletation.acknowledged
|
||||||
|
|
||||||
const ok = countDeletation.acknowledged && limitdeletation.acknowledged && projectDeletation.acknowledged
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok,
|
ok,
|
||||||
data: [
|
data: [
|
||||||
countDeletation.acknowledged,
|
countDeletation.acknowledged,
|
||||||
limitdeletation.acknowledged,
|
limitdeletation.acknowledged,
|
||||||
projectDeletation.acknowledged
|
projectDeletation.acknowledged,
|
||||||
|
sessionsDeletation.acknowledged,
|
||||||
|
notifiesDeletation.acknowledged,
|
||||||
|
aiChatsDeletation.acknowledged
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
38
dashboard/server/api/user/delete_account.delete.ts
Normal file
38
dashboard/server/api/user/delete_account.delete.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
import { ProjectModel } from "@schema/ProjectSchema";
|
||||||
|
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
||||||
|
import { ProjectLimitModel } from "@schema/ProjectsLimits";
|
||||||
|
import { UserSettingsModel } from "@schema/UserSettings";
|
||||||
|
import { AiChatModel } from "@schema/ai/AiChatSchema";
|
||||||
|
import { LimitNotifyModel } from "@schema/broker/LimitNotifySchema";
|
||||||
|
import { SessionModel } from "@schema/metrics/SessionSchema";
|
||||||
|
import StripeService from "~/server/services/StripeService";
|
||||||
|
|
||||||
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
const userData = getRequestUser(event);
|
||||||
|
if (!userData?.logged) return;
|
||||||
|
|
||||||
|
const projects = await ProjectModel.find({ owner: userData.id });
|
||||||
|
|
||||||
|
const premiumProjects = projects.filter(e => { return e.premium && e.premium_type != 0 }).length;
|
||||||
|
if (premiumProjects > 0) return setResponseStatus(event, 400, 'Cannot delete an account with a premium project');
|
||||||
|
|
||||||
|
for (const project of projects) {
|
||||||
|
const project_id = project._id;
|
||||||
|
await StripeService.deleteCustomer(project.customer_id);
|
||||||
|
const projectDeletation = await ProjectModel.deleteOne({ _id: project_id });
|
||||||
|
const userSettingsDeletation = await UserSettingsModel.deleteOne({ project_id });
|
||||||
|
|
||||||
|
const countDeletation = await ProjectCountModel.deleteMany({ project_id });
|
||||||
|
const limitdeletation = await ProjectLimitModel.deleteMany({ project_id });
|
||||||
|
const sessionsDeletation = await SessionModel.deleteMany({ project_id });
|
||||||
|
const notifiesDeletation = await LimitNotifyModel.deleteMany({ project_id });
|
||||||
|
const aiChatsDeletation = await AiChatModel.deleteMany({ project_id });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ok: true };
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user