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/configuration/+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/configuration/+server.ts')
| -rw-r--r-- | src/routes/api/configuration/+server.ts | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/src/routes/api/configuration/+server.ts b/src/routes/api/configuration/+server.ts index 10b6b09f..033e8dea 100644 --- a/src/routes/api/configuration/+server.ts +++ b/src/routes/api/configuration/+server.ts @@ -1,4 +1,5 @@ import { userIdentity } from "$lib/Data/AniList/identity"; +import { decodeAuthCookieOrThrow } from "$lib/Effect/authCookie"; import { deleteUserConfiguration, getUserConfiguration, @@ -22,22 +23,12 @@ export const PUT = async ({ cookies, request }) => { if (!userCookie) return unauthorised; - const user = JSON.parse(userCookie); + const user = decodeAuthCookieOrThrow(userCookie); return Response.json( - await setUserConfiguration( - ( - await userIdentity({ - tokenType: user["token_type"], - expiresIn: user["expires_in"], - accessToken: user["access_token"], - refreshToken: user["refresh_token"], - }) - ).id, - { - configuration: await request.json(), - }, - ), + await setUserConfiguration((await userIdentity(user)).id, { + configuration: await request.json(), + }), { headers: { "Access-Control-Allow-Origin": "https://due.moe", @@ -51,19 +42,10 @@ export const DELETE = async ({ cookies }) => { if (!userCookie) return unauthorised; - const user = JSON.parse(userCookie); + const user = decodeAuthCookieOrThrow(userCookie); return Response.json( - await deleteUserConfiguration( - ( - await userIdentity({ - tokenType: user["token_type"], - expiresIn: user["expires_in"], - accessToken: user["access_token"], - refreshToken: user["refresh_token"], - }) - ).id, - ), + await deleteUserConfiguration((await userIdentity(user)).id), { headers: { "Access-Control-Allow-Origin": "https://due.moe", |