Add auth schemas

This commit is contained in:
Alex Gleason 2024-10-12 17:56:35 -05:00
parent 943c5fddee
commit 02d599beab
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import { z } from 'zod';
import { tokenSchema } from 'soapbox/schemas/token';
import { coerceObject, filteredArray } from 'soapbox/schemas/utils';
const authUserSchema = z.object({
access_token: z.string(),
id: z.string(),
url: z.string().url(),
});
const soapboxAuthSchema = coerceObject({
tokens: filteredArray(tokenSchema),
users: filteredArray(authUserSchema),
me: z.string().url().nullable().catch(null),
});
type SoapboxAuth = z.infer<typeof soapboxAuthSchema>;
export { soapboxAuthSchema, SoapboxAuth };

12
src/schemas/token.ts Normal file
View File

@ -0,0 +1,12 @@
import { z } from 'zod';
const tokenSchema = z.object({
access_token: z.string(),
token_type: z.string(),
scope: z.string(),
created_at: z.number(),
});
type Token = z.infer<typeof tokenSchema>;
export { tokenSchema, Token };