diff options
| author | Fuwn <[email protected]> | 2026-03-03 08:57:37 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-03 08:57:53 -0800 |
| commit | 46d3463c220410a8db7d4d2f941f65d1621ff8d6 (patch) | |
| tree | 838949a51cbebcdba129695bfb693ad3bca0ec13 /src/routes/api/badges/+server.ts | |
| parent | refactor(effect): migrate core auth decode boundaries (diff) | |
| download | due.moe-46d3463c220410a8db7d4d2f941f65d1621ff8d6.tar.xz due.moe-46d3463c220410a8db7d4d2f941f65d1621ff8d6.zip | |
refactor(effect): migrate api auth cookie decoding
Diffstat (limited to 'src/routes/api/badges/+server.ts')
| -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")) |