mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Metadata fields should be set to null when left empty (#145)
This commit is contained in:
parent
aa654ccdc1
commit
088e980c38
@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
import { ServerUser } from '@stackframe/stack';
|
||||
import { standardProviders } from "@stackframe/stack-shared/dist/interface/clientInterface";
|
||||
import { jsonStringSchema } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { jsonStringOrEmptySchema, jsonStringSchema } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { ColumnDef, Row, Table } from "@tanstack/react-table";
|
||||
import { useMemo, useState } from "react";
|
||||
import * as yup from "yup";
|
||||
@ -55,8 +55,8 @@ const userEditFormSchema = yup.object({
|
||||
primaryEmail: yup.string().email("Primary Email must be a valid email address"),
|
||||
signedUpAt: yup.date().required(),
|
||||
primaryEmailVerified: yup.boolean().required(),
|
||||
clientMetadata: jsonStringSchema,
|
||||
serverMetadata: jsonStringSchema,
|
||||
clientMetadata: jsonStringOrEmptySchema.default("null"),
|
||||
serverMetadata: jsonStringOrEmptySchema.default("null"),
|
||||
});
|
||||
|
||||
function EditUserDialog(props: {
|
||||
@ -69,8 +69,8 @@ function EditUserDialog(props: {
|
||||
primaryEmail: props.user.primaryEmail || undefined,
|
||||
primaryEmailVerified: props.user.primaryEmailVerified,
|
||||
signedUpAt: props.user.signedUpAt,
|
||||
clientMetadata: props.user.clientMetadata ? JSON.stringify(props.user.clientMetadata) : undefined,
|
||||
serverMetadata: props.user.serverMetadata ? JSON.stringify(props.user.serverMetadata) : undefined,
|
||||
clientMetadata: props.user.clientMetadata == null ? "" : JSON.stringify(props.user.clientMetadata, null, 2),
|
||||
serverMetadata: props.user.serverMetadata == null ? "" : JSON.stringify(props.user.serverMetadata, null, 2),
|
||||
};
|
||||
|
||||
return <FormDialog
|
||||
@ -96,8 +96,8 @@ function EditUserDialog(props: {
|
||||
|
||||
<DateField control={form.control} label="Signed Up At" name="signedUpAt" />
|
||||
|
||||
<TextAreaField rows={3} control={form.control} label="Client Metadata" name="clientMetadata" />
|
||||
<TextAreaField rows={3} control={form.control} label="Server Metadata" name="serverMetadata" />
|
||||
<TextAreaField rows={3} control={form.control} label="Client Metadata" name="clientMetadata" placeholder="null" monospace />
|
||||
<TextAreaField rows={3} control={form.control} label="Server Metadata" name="serverMetadata" placeholder="null" monospace />
|
||||
</>
|
||||
)}
|
||||
onSubmit={async (values) => { await props.user.update({
|
||||
|
||||
@ -32,6 +32,7 @@ export function TextAreaField<F extends FieldValues>(props: {
|
||||
control: Control<F>,
|
||||
name: Path<F>,
|
||||
label: React.ReactNode,
|
||||
monospace?: boolean,
|
||||
}) {
|
||||
return (
|
||||
<FormField
|
||||
@ -47,6 +48,9 @@ export function TextAreaField<F extends FieldValues>(props: {
|
||||
rows={props.rows}
|
||||
placeholder={props.placeholder}
|
||||
value={field.value ?? ""}
|
||||
style={{
|
||||
fontFamily: props.monospace ? "ui-monospace, monospace" : undefined,
|
||||
}}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
|
||||
@ -94,6 +94,15 @@ export const jsonStringSchema = yupString().test("json", "Invalid JSON format",
|
||||
return false;
|
||||
}
|
||||
});
|
||||
export const jsonStringOrEmptySchema = yupString().test("json", "Invalid JSON format", (value) => {
|
||||
if (!value) return true;
|
||||
try {
|
||||
JSON.parse(value);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
export const emailSchema = yupString().email();
|
||||
|
||||
// Request auth
|
||||
|
||||
Loading…
Reference in New Issue
Block a user