mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-08 15:26:56 -05:00
fix(organization): On update, organization metadata shouldn't be stringified unless it's already an object.
This commit is contained in:
@@ -4,7 +4,7 @@ import { type WritableAtom } from "nanostores";
|
||||
import type { AtomListener, ClientOptions } from "./types";
|
||||
import { addCurrentURL, redirectPlugin } from "./fetch-plugins";
|
||||
import { getSessionAtom } from "./session-atom";
|
||||
import { betterJSON } from "./parser";
|
||||
import { parseJSON } from "./parser";
|
||||
|
||||
export const getClientConfig = <O extends ClientOptions>(options?: O) => {
|
||||
/* check if the credentials property is supported. Useful for cf workers */
|
||||
@@ -19,7 +19,7 @@ export const getClientConfig = <O extends ClientOptions>(options?: O) => {
|
||||
...(isCredentialsSupported ? { credentials: "include" } : {}),
|
||||
method: "GET",
|
||||
jsonParser(text) {
|
||||
return betterJSON(text, {
|
||||
return parseJSON(text, {
|
||||
strict: false,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -78,7 +78,7 @@ function parseISODate(value: string): Date | null {
|
||||
return isValidDate(date) ? date : null;
|
||||
}
|
||||
|
||||
export function betterJSONParse<T = unknown>(
|
||||
function betterJSONParse<T = unknown>(
|
||||
value: unknown,
|
||||
options: ParseOptions = {},
|
||||
): T {
|
||||
@@ -169,11 +169,11 @@ export function betterJSONParse<T = unknown>(
|
||||
}
|
||||
}
|
||||
|
||||
export function betterJSON<T = unknown>(
|
||||
export function parseJSON<T = unknown>(
|
||||
value: unknown,
|
||||
options: ParseOptions = { strict: true },
|
||||
): T {
|
||||
return betterJSONParse<T>(value, options);
|
||||
}
|
||||
|
||||
export default betterJSON;
|
||||
export default parseJSON;
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
} from "./schema";
|
||||
import { BetterAuthError } from "../../error";
|
||||
import type { AuthContext } from "../../types";
|
||||
import parseJSON from "../../client/parser";
|
||||
|
||||
export const getOrgAdapter = (
|
||||
context: AuthContext,
|
||||
@@ -239,7 +240,10 @@ export const getOrgAdapter = (
|
||||
],
|
||||
update: {
|
||||
...data,
|
||||
metadata: data.metadata ? JSON.stringify(data.metadata) : undefined,
|
||||
metadata:
|
||||
typeof data.metadata === "object"
|
||||
? JSON.stringify(data.metadata)
|
||||
: data.metadata,
|
||||
},
|
||||
});
|
||||
if (!organization) {
|
||||
@@ -248,7 +252,7 @@ export const getOrgAdapter = (
|
||||
return {
|
||||
...organization,
|
||||
metadata: organization.metadata
|
||||
? JSON.parse(organization.metadata)
|
||||
? parseJSON(organization.metadata)
|
||||
: undefined,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user