aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/notifications
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-07-25 00:13:29 -0700
committerFuwn <[email protected]>2024-07-25 00:13:29 -0700
commit3375311c1b92f615940412bb89ce81f644753996 (patch)
tree7c8143bc368f64481246d91a329606bb876f7682 /src/routes/api/notifications
parentfix(Settings): hint wording (diff)
downloaddue.moe-3375311c1b92f615940412bb89ce81f644753996.tar.xz
due.moe-3375311c1b92f615940412bb89ce81f644753996.zip
feat(notifications): allow unsubscribe
Diffstat (limited to 'src/routes/api/notifications')
-rw-r--r--src/routes/api/notifications/unsubscribe/+server.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/routes/api/notifications/unsubscribe/+server.ts b/src/routes/api/notifications/unsubscribe/+server.ts
new file mode 100644
index 00000000..f122625d
--- /dev/null
+++ b/src/routes/api/notifications/unsubscribe/+server.ts
@@ -0,0 +1,26 @@
+import { userIdentity } from '$lib/Data/AniList/identity';
+import { deleteUserSubscription } from '$lib/Database/userNotifications';
+
+const unauthorised = new Response('Unauthorised', { status: 401 });
+
+export const POST = async ({ cookies }) => {
+ const userCookie = cookies.get('user');
+
+ if (!userCookie) return unauthorised;
+
+ const user = JSON.parse(userCookie);
+ const userId = (
+ await userIdentity({
+ tokenType: user['token_type'],
+ expiresIn: user['expires_in'],
+ accessToken: user['access_token'],
+ refreshToken: user['refresh_token']
+ })
+ ).id;
+
+ if (!userId) return unauthorised;
+
+ await deleteUserSubscription(userId);
+
+ return new Response(null, { status: 200 });
+};