diff --git a/TODO b/TODO index aa60a98..7e11633 100644 --- a/TODO +++ b/TODO @@ -11,5 +11,4 @@ - generate state and check it against the state returned from lichess https://lichess.org/api#tag/oauth/GET/oauth - checkbox and toggle disabled states - 404 page -- lichess data with zod validation - react query on for study and chapter load, to allow caching \ No newline at end of file diff --git a/src/schemas.ts b/src/schemas.ts new file mode 100644 index 0000000..20203a3 --- /dev/null +++ b/src/schemas.ts @@ -0,0 +1,19 @@ +import { z } from "zod"; + +export const SessionSchema = z.object({ + username: z.string(), + id: z.string(), + token: z.string(), +}); + +export const TokenResponseSchema = z.object({ + access_token: z.string(), + expires_in: z.number().optional(), + scope: z.string().optional(), + token_type: z.string().optional(), +}); + +export const LichessAccountSchema = z.object({ + id: z.string(), + username: z.string(), +}); diff --git a/src/server/lichess.ts b/src/server/lichess.ts index c81a83f..9a2fe83 100644 --- a/src/server/lichess.ts +++ b/src/server/lichess.ts @@ -9,26 +9,11 @@ import { import { z } from "zod"; import { env } from "#/env.ts"; import { base64UrlEncode, sha256 } from "#/lib/encodeDecode.ts"; - -export const SessionSchema = z.object({ - username: z.string(), - id: z.string(), - token: z.string(), -}); - -const TokenResponseSchema = z.object({ - access_token: z.string(), - expires_in: z.number().optional(), - scope: z.string().optional(), - token_type: z.string().optional(), -}); - -const LichessAccountSchema = z.object({ - id: z.string(), - username: z.string(), -}); - -// export type Session = z.infer; +import { + LichessAccountSchema, + SessionSchema, + TokenResponseSchema, +} from "#/schemas.ts"; const createVerifier = () => base64UrlEncode(randomBytes(32)); const createChallenge = (verifier: string) => base64UrlEncode(sha256(verifier));