aboutsummaryrefslogtreecommitdiff
path: root/src/routes/api/preferences/badges/+server.ts
blob: 24d4924b02cff2572fff0f3f9ddb5d2cd2c6430d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { userIdentity } from '$lib/Data/AniList/identity';
import { toggleHideMissingBadges } from '$lib/Database/userPreferences';

const unauthorised = new Response('Unauthorised', { status: 401 });

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

	if (!userCookie) return unauthorised;

	const user = JSON.parse(userCookie);

	return Response.json(
		await toggleHideMissingBadges(
			(
				await userIdentity({
					tokenType: user['token_type'],
					expiresIn: user['expires_in'],
					accessToken: user['access_token'],
					refreshToken: user['refresh_token']
				})
			).id
		),
		{
			headers: {
				method: 'PUT',
				'Access-Control-Allow-Origin': 'https://due.moe'
			}
		}
	);
};