aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/badges/remove/+server.ts
blob: 8b05369a03134bfd376c5c853f06513c8de66ed8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { userIdentity } from '$lib/AniList/identity.js';
import { removeUserBadge } from '$lib/userBadgesDatabase.js';

export const POST = async ({ url, cookies }) => {
	const userCookie = cookies.get('user');

	if (!userCookie) {
		return new Response('Unauthenticated', { status: 401 });
	}

	const user = JSON.parse(userCookie);
	const identity = await userIdentity({
		tokenType: user['token_type'],
		expiresIn: user['expires_in'],
		accessToken: user['access_token'],
		refreshToken: user['refresh_token']
	});

	removeUserBadge(identity.id, Number(url.searchParams.get('id')));

	return Response.json({});
};