From 4c77ab108ccddc8123f8b32bf765ed4e18749029 Mon Sep 17 00:00:00 2001
From: slugb0t
Date: Wed, 11 Dec 2024 11:54:35 -0800
Subject: [PATCH] feat: :sparkles: purge zenodo token when sign in is required
---
ui/components.d.ts | 5 ----
.../[owner]/[repo]/release/zenodo.vue | 21 +++++++++++++++-
ui/server/api/user/zenodo.delete.ts | 25 +++++++++++++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
create mode 100644 ui/server/api/user/zenodo.delete.ts
diff --git a/ui/components.d.ts b/ui/components.d.ts
index 3153f64b..01eda1f3 100644
--- a/ui/components.d.ts
+++ b/ui/components.d.ts
@@ -17,23 +17,18 @@ declare module 'vue' {
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCollapse: typeof import('naive-ui')['NCollapse']
NCollapseItem: typeof import('naive-ui')['NCollapseItem']
- NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
- NDatePicker: typeof import('naive-ui')['NDatePicker']
NDivider: typeof import('naive-ui')['NDivider']
NDropdown: typeof import('naive-ui')['NDropdown']
- NDynamicInput: typeof import('naive-ui')['NDynamicInput']
NFlex: typeof import('naive-ui')['NFlex']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NInput: typeof import('naive-ui')['NInput']
NModal: typeof import('naive-ui')['NModal']
- NPopconfirm: typeof import('naive-ui')['NPopconfirm']
NPopover: typeof import('naive-ui')['NPopover']
NRadio: typeof import('naive-ui')['NRadio']
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NSelect: typeof import('naive-ui')['NSelect']
- NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NTag: typeof import('naive-ui')['NTag']
NTooltip: typeof import('naive-ui')['NTooltip']
diff --git a/ui/pages/dashboard/[owner]/[repo]/release/zenodo.vue b/ui/pages/dashboard/[owner]/[repo]/release/zenodo.vue
index c6c120a2..3e247357 100644
--- a/ui/pages/dashboard/[owner]/[repo]/release/zenodo.vue
+++ b/ui/pages/dashboard/[owner]/[repo]/release/zenodo.vue
@@ -500,6 +500,25 @@ const validateZenodoForm = () => {
});
};
+const loginToZenodo = () => {
+ // Send api request to purge the Zenodo token
+ $fetch(`/api/user/zenodo`, {
+ headers: useRequestHeaders(["cookie"]),
+ method: "DELETE",
+ })
+ .then(() => {
+ // Redirect to the Zenodo login page
+ window.location.href = zenodoLoginUrl.value;
+ })
+ .catch((error) => {
+ console.error("Failed to purge Zenodo token:", error);
+ push.error({
+ title: "Failed to purge Zenodo token",
+ message: "Please try again later",
+ });
+ });
+}
+
const githubReleaseInterval = ref(null);
onMounted(() => {
@@ -760,7 +779,7 @@ onBeforeUnmount(() => {
login to Zenodo to continue.
-
+
diff --git a/ui/server/api/user/zenodo.delete.ts b/ui/server/api/user/zenodo.delete.ts
new file mode 100644
index 00000000..729682de
--- /dev/null
+++ b/ui/server/api/user/zenodo.delete.ts
@@ -0,0 +1,25 @@
+import type { User } from "lucia";
+
+export default defineEventHandler(async (event) => {
+ protectRoute(event);
+
+ const user = event.context.user as User | null;
+
+ if (!user) {
+ throw createError({
+ statusCode: 400,
+ statusMessage: "Bad Request. Missing user in the URL params",
+ });
+ }
+
+ // Delete only the Zenodo token from the zenodoToken table
+ await prisma.zenodoToken.deleteMany({
+ where: {
+ user_id: user.id,
+ },
+ });
+
+ return {
+ message: "Zenodo token purged",
+ };
+});