mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 18:16:38 +00:00
a02037ae1c
Fixes #1016 ## Description: Fix the zod user schema validation to make roles optional. This was causing a validation error when looking up the user's roles. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { z } from "zod";
|
|
import { base64urlToUuid } from "./Base64";
|
|
|
|
export const RefreshResponseSchema = z.object({
|
|
token: z.string(),
|
|
});
|
|
export type RefreshResponse = z.infer<typeof RefreshResponseSchema>;
|
|
|
|
export const TokenPayloadSchema = z.object({
|
|
jti: z.string(),
|
|
sub: z
|
|
.string()
|
|
.refine(
|
|
(val) => {
|
|
const uuid = base64urlToUuid(val);
|
|
return !!uuid;
|
|
},
|
|
{
|
|
message: "Invalid base64-encoded UUID",
|
|
},
|
|
)
|
|
.transform((val) => {
|
|
const uuid = base64urlToUuid(val);
|
|
if (!uuid) throw new Error("Invalid base64 UUID");
|
|
return uuid;
|
|
}),
|
|
iat: z.number(),
|
|
iss: z.string(),
|
|
aud: z.string(),
|
|
exp: z.number(),
|
|
});
|
|
export type TokenPayload = z.infer<typeof TokenPayloadSchema>;
|
|
|
|
export const UserMeResponseSchema = z.object({
|
|
user: z.object({
|
|
id: z.string(),
|
|
avatar: z.string().nullable(),
|
|
username: z.string(),
|
|
global_name: z.string().nullable(),
|
|
discriminator: z.string(),
|
|
locale: z.string().optional(),
|
|
}),
|
|
player: z.object({
|
|
publicId: z.string(),
|
|
roles: z.string().array().optional(),
|
|
}),
|
|
});
|
|
export type UserMeResponse = z.infer<typeof UserMeResponseSchema>;
|