@progalaxyelabs/ngx-stonescriptphp-client 1.12.0 → 1.14.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.
|
@@ -469,7 +469,7 @@ class StoneScriptPHPAuth {
|
|
|
469
469
|
return [];
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
async registerTenant(data
|
|
472
|
+
async registerTenant(data) {
|
|
473
473
|
if (data.provider !== 'emailPassword') {
|
|
474
474
|
return this.registerTenantWithOAuth(data.tenantName, data.provider);
|
|
475
475
|
}
|
|
@@ -489,14 +489,15 @@ class StoneScriptPHPAuth {
|
|
|
489
489
|
body['role'] = data.role;
|
|
490
490
|
const response = await fetch(`${apiUrl}/auth/register-tenant`, {
|
|
491
491
|
method: 'POST',
|
|
492
|
-
headers: {
|
|
493
|
-
'Content-Type': 'application/json',
|
|
494
|
-
...(accessToken ? { 'Authorization': `Bearer ${accessToken}` } : {})
|
|
495
|
-
},
|
|
492
|
+
headers: { 'Content-Type': 'application/json' },
|
|
496
493
|
credentials: 'include',
|
|
497
494
|
body: JSON.stringify(body)
|
|
498
495
|
});
|
|
499
|
-
|
|
496
|
+
const result = await response.json();
|
|
497
|
+
if (result?.status === 'ok' || result?.success === true) {
|
|
498
|
+
return { success: true };
|
|
499
|
+
}
|
|
500
|
+
return { success: false, message: result?.data?.message || result?.message || 'Registration failed' };
|
|
500
501
|
}
|
|
501
502
|
catch {
|
|
502
503
|
return { success: false, message: 'Network error. Please try again.' };
|
|
@@ -522,8 +523,11 @@ class StoneScriptPHPAuth {
|
|
|
522
523
|
if (event.data.type === 'tenant_register_success') {
|
|
523
524
|
window.removeEventListener('message', messageHandler);
|
|
524
525
|
popup.close();
|
|
525
|
-
resolve({
|
|
526
|
-
|
|
526
|
+
resolve({
|
|
527
|
+
success: true,
|
|
528
|
+
accessToken: event.data.access_token,
|
|
529
|
+
user: event.data.user ? this.normalizeUser(event.data.user) : undefined
|
|
530
|
+
});
|
|
527
531
|
}
|
|
528
532
|
else if (event.data.type === 'tenant_register_error') {
|
|
529
533
|
window.removeEventListener('message', messageHandler);
|
|
@@ -969,16 +973,20 @@ class AuthService {
|
|
|
969
973
|
if (!this.plugin.registerTenant) {
|
|
970
974
|
return { success: false, message: 'registerTenant not supported by the configured auth plugin' };
|
|
971
975
|
}
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
976
|
+
const registered = await this.plugin.registerTenant(data);
|
|
977
|
+
if (!registered.success)
|
|
978
|
+
return registered;
|
|
979
|
+
// OAuth: token comes directly from the popup — store it and we're done.
|
|
980
|
+
if (registered.accessToken) {
|
|
981
|
+
this.storeAuthResult(registered);
|
|
982
|
+
return registered;
|
|
977
983
|
}
|
|
978
|
-
|
|
979
|
-
|
|
984
|
+
// emailPassword: registration succeeded but no token yet.
|
|
985
|
+
// Login via auth (SSO) to obtain tokens.
|
|
986
|
+
if (data.provider === 'emailPassword' && data.email && data.password) {
|
|
987
|
+
return await this.loginWithEmail(data.email, data.password);
|
|
980
988
|
}
|
|
981
|
-
return
|
|
989
|
+
return registered;
|
|
982
990
|
}
|
|
983
991
|
async getTenantMemberships(serverName) {
|
|
984
992
|
if (!this.plugin.getTenantMemberships)
|
|
@@ -3249,12 +3257,9 @@ class TenantRegisterComponent {
|
|
|
3249
3257
|
tenantName: this.tenantName,
|
|
3250
3258
|
provider: provider
|
|
3251
3259
|
});
|
|
3252
|
-
if (result.success && result.
|
|
3260
|
+
if (result.success && result.user) {
|
|
3253
3261
|
this.success = 'Organization created successfully!';
|
|
3254
|
-
this.tenantCreated.emit({
|
|
3255
|
-
tenant: result.tenant,
|
|
3256
|
-
user: result.user
|
|
3257
|
-
});
|
|
3262
|
+
this.tenantCreated.emit({ user: result.user });
|
|
3258
3263
|
}
|
|
3259
3264
|
else {
|
|
3260
3265
|
this.error = result.message || 'Registration failed';
|
|
@@ -3284,12 +3289,9 @@ class TenantRegisterComponent {
|
|
|
3284
3289
|
password: this.password,
|
|
3285
3290
|
provider: 'emailPassword'
|
|
3286
3291
|
});
|
|
3287
|
-
if (result.success && result.
|
|
3292
|
+
if (result.success && result.user) {
|
|
3288
3293
|
this.success = 'Organization created successfully!';
|
|
3289
|
-
this.tenantCreated.emit({
|
|
3290
|
-
tenant: result.tenant,
|
|
3291
|
-
user: result.user
|
|
3292
|
-
});
|
|
3294
|
+
this.tenantCreated.emit({ user: result.user });
|
|
3293
3295
|
}
|
|
3294
3296
|
else {
|
|
3295
3297
|
this.error = result.message || 'Registration failed';
|