@@ -194,15 +194,15 @@ export async function getUserAttributes(req, getAll = false) {
194194 return response . json ( ) ;
195195 } )
196196 . then ( ( data ) => {
197- for ( let key in data . attributes ) {
198- data . attributes [ key ] = data . attributes [ key ] [ 0 ] ;
197+ for ( let key in data ) {
198+ data [ key ] = data [ key ] [ 0 ] ;
199199 }
200200 if ( getAll ) {
201201 // Remove fields from the object that are not needed.
202202 let { userProfileMetadata, id, username, emailVerified, ...d } = data ;
203203 return d ;
204204 }
205- return data . attributes ;
205+ return data ;
206206 } )
207207 . catch ( ( error ) => {
208208 console . error ( "Error fetching current attributes:" , error ) ;
@@ -212,7 +212,7 @@ export async function getUserAttributes(req, getAll = false) {
212212}
213213
214214export async function setUserAttribute ( req , attributeName , attributeValue ) {
215- if ( ! req || ! req . user || ! req . user . accessToken || ! req . user . keycloakConfig ) {
215+ if ( ! req || ! req . user || ! req . user . accessToken || ! req . user . keycloakConfig ) {
216216 return null ;
217217 }
218218 const keycloakConfig = req . user . keycloakConfig ;
@@ -223,10 +223,12 @@ export async function setUserAttribute(req, attributeName, attributeValue) {
223223 // Fetch current user attributes
224224 const currentAttributes = await getUserAttributes ( req , true ) ;
225225
226- // Merge current and new attributes
227- const mas = { ...currentAttributes . attributes , [ attributeName ] : attributeValue } ;
228- const mergedAttributes = { ...currentAttributes , attributes : mas } ;
229-
226+ // Merge current and new attributes at the root level
227+ let mergedAttributes = { ...currentAttributes , [ attributeName ] : attributeValue } ;
228+ mergedAttributes = {
229+ attributes : mergedAttributes
230+ }
231+
230232 const result = fetch ( url , {
231233 method : "POST" ,
232234 headers : {
0 commit comments