@frontegg/rest-api 7.100.0 → 7.101.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/index.js +24 -4
- package/index.js +1 -1
- package/node/auth/index.js +24 -4
- package/node/index.js +1 -1
- package/package.json +1 -1
package/auth/index.js
CHANGED
|
@@ -67,14 +67,24 @@ export class AuthenticationApi extends BaseApiClient {
|
|
|
67
67
|
const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), getCurrentUserTenantsFunction(this.appName)()]);
|
|
68
68
|
const decodedContent = accessToken ? jwtDecode(accessToken) : {};
|
|
69
69
|
const user = _extends({}, loginResponse, decodedContent, me);
|
|
70
|
-
|
|
70
|
+
let {
|
|
71
|
+
activeTenant
|
|
72
|
+
} = currentUserTenants;
|
|
73
|
+
if (contextHolder.isSessionPerTenantEnabled() && decodedContent.tenantId) {
|
|
74
|
+
user.tenantId = decodedContent.tenantId;
|
|
71
75
|
setTabTenantInSessionStorage(user.tenantId);
|
|
76
|
+
// The server's activeTenant may reflect a different tab's tenant switch.
|
|
77
|
+
// Correct it to match the JWT's tenant for this tab.
|
|
78
|
+
const matchingTenant = currentUserTenants.tenants.find(t => t.tenantId === decodedContent.tenantId);
|
|
79
|
+
if (matchingTenant) {
|
|
80
|
+
activeTenant = matchingTenant;
|
|
81
|
+
}
|
|
72
82
|
}
|
|
73
83
|
contextHolder.setUser(user);
|
|
74
84
|
return {
|
|
75
85
|
user,
|
|
76
86
|
tenants: currentUserTenants.tenants,
|
|
77
|
-
activeTenant
|
|
87
|
+
activeTenant
|
|
78
88
|
};
|
|
79
89
|
};
|
|
80
90
|
this.generateLoginResponseFromOAuthResponse = async oauthResponse => {
|
|
@@ -104,14 +114,24 @@ export class AuthenticationApi extends BaseApiClient {
|
|
|
104
114
|
}, decodedContent, me, {
|
|
105
115
|
expiresIn: oauthResponse.expires_in || 300
|
|
106
116
|
});
|
|
107
|
-
|
|
117
|
+
let {
|
|
118
|
+
activeTenant
|
|
119
|
+
} = currentUserTenants;
|
|
120
|
+
if (contextHolder.isSessionPerTenantEnabled() && decodedContent.tenantId) {
|
|
121
|
+
user.tenantId = decodedContent.tenantId;
|
|
108
122
|
setTabTenantInSessionStorage(user.tenantId);
|
|
123
|
+
// The server's activeTenant may reflect a different tab's tenant switch.
|
|
124
|
+
// Correct it to match the JWT's tenant for this tab.
|
|
125
|
+
const matchingTenant = currentUserTenants.tenants.find(t => t.tenantId === decodedContent.tenantId);
|
|
126
|
+
if (matchingTenant) {
|
|
127
|
+
activeTenant = matchingTenant;
|
|
128
|
+
}
|
|
109
129
|
}
|
|
110
130
|
contextHolder.setUser(user);
|
|
111
131
|
return {
|
|
112
132
|
user,
|
|
113
133
|
tenants: currentUserTenants.tenants,
|
|
114
|
-
activeTenant
|
|
134
|
+
activeTenant
|
|
115
135
|
};
|
|
116
136
|
};
|
|
117
137
|
this.preLogin = async body => {
|
package/index.js
CHANGED
package/node/auth/index.js
CHANGED
|
@@ -132,14 +132,24 @@ class AuthenticationApi extends _BaseApiClient.BaseApiClient {
|
|
|
132
132
|
const [me, currentUserTenants] = await Promise.all([this.getMeAndEntitlements(), (0, _utils.getCurrentUserTenantsFunction)(this.appName)()]);
|
|
133
133
|
const decodedContent = accessToken ? (0, _jwt.jwtDecode)(accessToken) : {};
|
|
134
134
|
const user = (0, _extends2.default)({}, loginResponse, decodedContent, me);
|
|
135
|
-
|
|
135
|
+
let {
|
|
136
|
+
activeTenant
|
|
137
|
+
} = currentUserTenants;
|
|
138
|
+
if (contextHolder.isSessionPerTenantEnabled() && decodedContent.tenantId) {
|
|
139
|
+
user.tenantId = decodedContent.tenantId;
|
|
136
140
|
(0, _utils.setTabTenantInSessionStorage)(user.tenantId);
|
|
141
|
+
// The server's activeTenant may reflect a different tab's tenant switch.
|
|
142
|
+
// Correct it to match the JWT's tenant for this tab.
|
|
143
|
+
const matchingTenant = currentUserTenants.tenants.find(t => t.tenantId === decodedContent.tenantId);
|
|
144
|
+
if (matchingTenant) {
|
|
145
|
+
activeTenant = matchingTenant;
|
|
146
|
+
}
|
|
137
147
|
}
|
|
138
148
|
contextHolder.setUser(user);
|
|
139
149
|
return {
|
|
140
150
|
user,
|
|
141
151
|
tenants: currentUserTenants.tenants,
|
|
142
|
-
activeTenant
|
|
152
|
+
activeTenant
|
|
143
153
|
};
|
|
144
154
|
};
|
|
145
155
|
this.generateLoginResponseFromOAuthResponse = async oauthResponse => {
|
|
@@ -169,14 +179,24 @@ class AuthenticationApi extends _BaseApiClient.BaseApiClient {
|
|
|
169
179
|
}, decodedContent, me, {
|
|
170
180
|
expiresIn: oauthResponse.expires_in || 300
|
|
171
181
|
});
|
|
172
|
-
|
|
182
|
+
let {
|
|
183
|
+
activeTenant
|
|
184
|
+
} = currentUserTenants;
|
|
185
|
+
if (contextHolder.isSessionPerTenantEnabled() && decodedContent.tenantId) {
|
|
186
|
+
user.tenantId = decodedContent.tenantId;
|
|
173
187
|
(0, _utils.setTabTenantInSessionStorage)(user.tenantId);
|
|
188
|
+
// The server's activeTenant may reflect a different tab's tenant switch.
|
|
189
|
+
// Correct it to match the JWT's tenant for this tab.
|
|
190
|
+
const matchingTenant = currentUserTenants.tenants.find(t => t.tenantId === decodedContent.tenantId);
|
|
191
|
+
if (matchingTenant) {
|
|
192
|
+
activeTenant = matchingTenant;
|
|
193
|
+
}
|
|
174
194
|
}
|
|
175
195
|
contextHolder.setUser(user);
|
|
176
196
|
return {
|
|
177
197
|
user,
|
|
178
198
|
tenants: currentUserTenants.tenants,
|
|
179
|
-
activeTenant
|
|
199
|
+
activeTenant
|
|
180
200
|
};
|
|
181
201
|
};
|
|
182
202
|
this.preLogin = async body => {
|
package/node/index.js
CHANGED