@progalaxyelabs/ngx-stonescriptphp-client 1.14.0 → 1.15.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.
|
@@ -140,19 +140,36 @@ class StoneScriptPHPAuth {
|
|
|
140
140
|
const raw = this.resolvePath(data, this.responseMap.userPath);
|
|
141
141
|
return raw ? this.normalizeUser(raw) : undefined;
|
|
142
142
|
}
|
|
143
|
+
resolveMembership(data) {
|
|
144
|
+
const raw = this.resolvePath(data, 'data.membership');
|
|
145
|
+
return raw ? raw : undefined;
|
|
146
|
+
}
|
|
143
147
|
resolveErrorMessage(data, fallback) {
|
|
144
148
|
const path = this.responseMap.errorMessagePath ?? 'message';
|
|
145
149
|
return this.resolvePath(data, path) || fallback;
|
|
146
150
|
}
|
|
147
151
|
normalizeUser(raw) {
|
|
148
|
-
|
|
149
|
-
user_id: raw.user_id ?? (raw.id ? this.hashUUID(raw.id) : 0),
|
|
150
|
-
id: raw.id ?? String(raw.user_id),
|
|
152
|
+
const user = {
|
|
151
153
|
email: raw.email,
|
|
152
154
|
display_name: raw.display_name ?? raw.email?.split('@')[0] ?? '',
|
|
153
155
|
photo_url: raw.photo_url,
|
|
154
156
|
is_email_verified: raw.is_email_verified ?? false
|
|
155
157
|
};
|
|
158
|
+
// id and user_id are optional after auth response cleanup (task #1552)
|
|
159
|
+
// Only populate them if the raw data contains them
|
|
160
|
+
if (raw.id) {
|
|
161
|
+
user.id = raw.id;
|
|
162
|
+
}
|
|
163
|
+
else if (raw.user_id) {
|
|
164
|
+
user.id = String(raw.user_id);
|
|
165
|
+
}
|
|
166
|
+
if (raw.user_id) {
|
|
167
|
+
user.user_id = raw.user_id;
|
|
168
|
+
}
|
|
169
|
+
else if (raw.id) {
|
|
170
|
+
user.user_id = this.hashUUID(raw.id);
|
|
171
|
+
}
|
|
172
|
+
return user;
|
|
156
173
|
}
|
|
157
174
|
hashUUID(uuid) {
|
|
158
175
|
let hash = 0;
|
|
@@ -249,7 +266,8 @@ class StoneScriptPHPAuth {
|
|
|
249
266
|
success: true,
|
|
250
267
|
accessToken: this.resolveAccessToken(data),
|
|
251
268
|
refreshToken: this.resolveRefreshToken(data),
|
|
252
|
-
user: this.resolveUser(data)
|
|
269
|
+
user: this.resolveUser(data),
|
|
270
|
+
membership: this.resolveMembership(data)
|
|
253
271
|
};
|
|
254
272
|
}
|
|
255
273
|
return { success: false, message: this.resolveErrorMessage(data, 'Invalid credentials') };
|
|
@@ -454,7 +472,8 @@ class StoneScriptPHPAuth {
|
|
|
454
472
|
async getTenantMemberships(accessToken) {
|
|
455
473
|
try {
|
|
456
474
|
const accountsUrl = this.getAccountsUrl();
|
|
457
|
-
const
|
|
475
|
+
const platformCode = encodeURIComponent(this.config.platformCode ?? '');
|
|
476
|
+
const response = await fetch(`${accountsUrl}/api/auth/memberships?platform_code=${platformCode}`, {
|
|
458
477
|
method: 'GET',
|
|
459
478
|
headers: {
|
|
460
479
|
'Authorization': `Bearer ${accessToken}`,
|
|
@@ -1830,8 +1849,8 @@ class TenantLoginComponent {
|
|
|
1830
1849
|
this.error = result.message || 'Login failed';
|
|
1831
1850
|
return;
|
|
1832
1851
|
}
|
|
1833
|
-
// Authentication successful
|
|
1834
|
-
await this.handlePostAuthFlow();
|
|
1852
|
+
// Authentication successful — pass result so membership can be reused
|
|
1853
|
+
await this.handlePostAuthFlow(result);
|
|
1835
1854
|
}
|
|
1836
1855
|
catch (err) {
|
|
1837
1856
|
this.error = err.message || 'An unexpected error occurred';
|
|
@@ -1849,8 +1868,8 @@ class TenantLoginComponent {
|
|
|
1849
1868
|
this.error = result.message || 'OAuth login failed';
|
|
1850
1869
|
return;
|
|
1851
1870
|
}
|
|
1852
|
-
// Authentication successful
|
|
1853
|
-
await this.handlePostAuthFlow();
|
|
1871
|
+
// Authentication successful — pass result so membership can be reused if present
|
|
1872
|
+
await this.handlePostAuthFlow(result);
|
|
1854
1873
|
}
|
|
1855
1874
|
catch (err) {
|
|
1856
1875
|
this.error = err.message || 'An unexpected error occurred';
|
|
@@ -1859,7 +1878,7 @@ class TenantLoginComponent {
|
|
|
1859
1878
|
this.loading = false;
|
|
1860
1879
|
}
|
|
1861
1880
|
}
|
|
1862
|
-
async handlePostAuthFlow() {
|
|
1881
|
+
async handlePostAuthFlow(loginResult) {
|
|
1863
1882
|
if (!this.showTenantSelector) {
|
|
1864
1883
|
// Tenant selection is disabled, emit event immediately
|
|
1865
1884
|
this.tenantSelected.emit({
|
|
@@ -1869,11 +1888,20 @@ class TenantLoginComponent {
|
|
|
1869
1888
|
});
|
|
1870
1889
|
return;
|
|
1871
1890
|
}
|
|
1872
|
-
//
|
|
1891
|
+
// Resolve memberships — prefer data from login response to avoid extra API call
|
|
1873
1892
|
this.loading = true;
|
|
1874
1893
|
try {
|
|
1875
|
-
|
|
1876
|
-
if (
|
|
1894
|
+
let memberships;
|
|
1895
|
+
if (loginResult?.membership) {
|
|
1896
|
+
// Login response already included membership — use it directly
|
|
1897
|
+
memberships = [loginResult.membership];
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
// Fall back to fetching memberships from API (with platform_code param)
|
|
1901
|
+
const result = await this.auth.getTenantMemberships();
|
|
1902
|
+
memberships = result.memberships;
|
|
1903
|
+
}
|
|
1904
|
+
if (!memberships || memberships.length === 0) {
|
|
1877
1905
|
// User has no tenants, prompt to create one
|
|
1878
1906
|
this.error = 'You are not a member of any organization. Please create one.';
|
|
1879
1907
|
if (this.allowTenantCreation) {
|
|
@@ -1881,7 +1909,7 @@ class TenantLoginComponent {
|
|
|
1881
1909
|
}
|
|
1882
1910
|
return;
|
|
1883
1911
|
}
|
|
1884
|
-
this.memberships =
|
|
1912
|
+
this.memberships = memberships;
|
|
1885
1913
|
// Get user name if available
|
|
1886
1914
|
const currentUser = this.auth.getCurrentUser();
|
|
1887
1915
|
if (currentUser) {
|