diff options
Diffstat (limited to 'src/routes/api/badges')
| -rw-r--r-- | src/routes/api/badges/+server.ts | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/routes/api/badges/+server.ts b/src/routes/api/badges/+server.ts index 3c389cf6..abd5c0cd 100644 --- a/src/routes/api/badges/+server.ts +++ b/src/routes/api/badges/+server.ts @@ -1,4 +1,5 @@ import { userIdentity } from "$lib/Data/AniList/identity"; +import { decodeAuthCookieOrThrow } from "$lib/Effect/authCookie"; import { removeAllUserBadges, removeUserBadge, @@ -31,13 +32,8 @@ export const DELETE = async ({ url, cookies }) => { if (!userCookie) return unauthorised; - 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"], - }); + const user = decodeAuthCookieOrThrow(userCookie); + const identity = await userIdentity(user); if ((url.searchParams.get("prune") || 0) === "true") { await removeAllUserBadges(identity.id); @@ -61,13 +57,8 @@ export const PUT = async ({ cookies, url, request }) => { if (!userCookie) return unauthorised; - 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"], - }); + const user = decodeAuthCookieOrThrow(userCookie); + const identity = await userIdentity(user); const authorised = privilegedUser(identity.id); if (url.searchParams.get("shadowHide")) |