From 8a99dd5c4b74a4ea2ce715aed5e517022621f05c Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 28 Mar 2026 06:02:54 +0000 Subject: fix(auth): ignore malformed user cookies --- src/lib/Effect/authCookie.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/lib/Effect/authCookie.ts') diff --git a/src/lib/Effect/authCookie.ts b/src/lib/Effect/authCookie.ts index e716f5e9..f407216e 100644 --- a/src/lib/Effect/authCookie.ts +++ b/src/lib/Effect/authCookie.ts @@ -2,10 +2,10 @@ import type { AniListAuthorisation } from "$lib/Data/AniList/identity"; import { Effect, Result, Schema } from "effect"; const UserCookieSchema = Schema.Struct({ - token_type: Schema.String, + token_type: Schema.NonEmptyString, expires_in: Schema.Number, - access_token: Schema.String, - refresh_token: Schema.String, + access_token: Schema.NonEmptyString, + refresh_token: Schema.NonEmptyString, }); export const decodeAuthCookieEffect = (cookie: string) => @@ -43,3 +43,11 @@ export const decodeAuthCookieOrThrow = ( return Result.getOrThrow(decoded); }; + +export const decodeAuthCookieOrNull = ( + cookie: string, +): AniListAuthorisation | null => { + const decoded = decodeAuthCookieEither(cookie); + + return Result.isSuccess(decoded) ? decoded.success : null; +}; -- cgit v1.2.3