@@ -13,22 +13,32 @@ const getOrgProperty = (
13
13
idToken : KindeIdToken ,
14
14
accessToken : KindeAccessToken ,
15
15
) : string | undefined => {
16
- const idValue = idToken . organization_properties ?. [ `kp_org_${ key } ` ] ?. v ;
17
- const accessValue = accessToken . organization_properties ?. [ `kp_org_${ key } ` ] ?. v ;
16
+ const orgIdTokenProperties =
17
+ idToken . organization_properties ||
18
+ idToken [ "x-hasura-organization_properties" ] ||
19
+ { } ;
20
+ const orgAccessTokenProperties =
21
+ accessToken . organization_properties ||
22
+ accessToken [ "x-hasura-organization_properties" ] ||
23
+ { } ;
24
+ const idValue = orgIdTokenProperties [ `kp_org_${ key } ` ] ?. v ;
25
+ const accessValue = orgAccessTokenProperties [ `kp_org_${ key } ` ] ?. v ;
18
26
return idValue || accessValue ;
19
27
} ;
20
28
21
29
export const generateOrganizationObject = (
22
30
idToken : KindeIdToken ,
23
31
accessToken : KindeAccessToken ,
24
32
) => {
25
- if ( ! accessToken . org_code ) {
33
+ const orgCode = accessToken . org_code || accessToken [ "x-hasura-org-code" ] ;
34
+ const orgName = accessToken . org_name || accessToken [ "x-hasura-org-name" ] ;
35
+ if ( ! orgCode ) {
26
36
throw new Error ( "Missing required organization fields in access token" ) ;
27
37
}
28
38
29
39
return {
30
- orgCode : accessToken . org_code ,
31
- orgName : accessToken . org_name ,
40
+ orgCode,
41
+ orgName,
32
42
properties : {
33
43
city : getOrgProperty ( "city" , idToken , accessToken ) ,
34
44
industry : getOrgProperty ( "industry" , idToken , accessToken ) ,
0 commit comments