Skip to content

Commit c1fe372

Browse files
fix(nextjs): Remove organization private metadata from __NEXT_DATA__
This allows for sensitive fields like `organization.privateMetadata` to be available inside the `withServerSideAuth` callback while ensuring that these fields will not get serialized into the client-accessible __NEXT_DATA__ script.
1 parent a8ff80d commit c1fe372

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/nextjs/src/middleware/utils/sanitizeAuthData.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AuthData } from '../types';
22

33
/**
44
*
5-
* Removes sensitive data from User and Session
5+
* Removes sensitive data from User and Organization
66
* This allows for sensitive fields like `user.privateMetadata` to be available
77
* inside the `withServerSideAuth` callback, while ensuring that these fields
88
* will not get serialized into the client-accessible __NEXT_DATA__ script
@@ -15,5 +15,12 @@ export function sanitizeAuthData(authData: AuthData): any {
1515
// @ts-expect-error;
1616
delete user['privateMetadata'];
1717
}
18-
return { ...authData, user };
18+
19+
const organization = authData.organization ? { ...authData.organization } : authData.organization;
20+
if (organization) {
21+
// @ts-expect-error;
22+
delete organization['privateMetadata'];
23+
}
24+
25+
return { ...authData, user, organization };
1926
}

0 commit comments

Comments
 (0)