@progalaxyelabs/ngx-stonescriptphp-client 1.18.1 → 1.18.3

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/README.md CHANGED
@@ -74,6 +74,37 @@ authProviders: {
74
74
 
75
75
  See [Configuration](#configuration) and [AUTH-PROVIDER-CONFIG.md](AUTH-PROVIDER-CONFIG.md) for details.
76
76
 
77
+ ### Accessing User Info
78
+
79
+ After login or registration, the library stores the authenticated user. Access it in any component:
80
+
81
+ ```typescript
82
+ import { AuthService, User } from '@progalaxyelabs/ngx-stonescriptphp-client';
83
+
84
+ @Component({ ... })
85
+ export class MyComponent {
86
+ constructor(private authService: AuthService) {}
87
+
88
+ ngOnInit() {
89
+ // Snapshot — current user or null if not authenticated
90
+ const user: User | null = this.authService.getCurrentUser();
91
+ if (user) {
92
+ console.log(user.display_name); // "John Doe"
93
+ console.log(user.email); // "john@example.com"
94
+ console.log(user.photo_url); // avatar URL (optional)
95
+ console.log(user.is_email_verified);
96
+ }
97
+
98
+ // Reactive — emits on login, logout, and token refresh
99
+ this.authService.user$.subscribe(user => {
100
+ // user is User | null
101
+ });
102
+ }
103
+ }
104
+ ```
105
+
106
+ The `User` object is persisted in localStorage and restored on page refresh. It is populated from the auth service API response (not from the JWT token).
107
+
77
108
  📖 **Documentation**: [CHANGELOG](docs/CHANGELOG.md) | [Auth Compatibility](docs/AUTH_COMPATIBILITY.md) | [Provider Config](AUTH-PROVIDER-CONFIG.md) | [Modal Auth Spec](MODAL-AUTH-SPEC.md) | [Multi-Auth Server](MULTI-AUTH-SERVER.md)
78
109
 
79
110
  ---
@@ -835,16 +835,18 @@ class ProgalaxyElabsAuth {
835
835
  }
836
836
  // -- Internal helpers -----------------------------------------------------
837
837
  handleLoginResponse(data) {
838
- // New identity — needs onboarding
839
- if (data.is_new_identity) {
838
+ // Identity with no tenant memberships — needs onboarding
839
+ // Covers both new registration (is_new_identity=true) and
840
+ // returning user who hasn't created a tenant yet (is_new_identity=false, memberships=[])
841
+ if (data.identity && (!data.membership)) {
840
842
  return {
841
843
  success: true,
842
844
  accessToken: data.access_token,
843
845
  refreshToken: data.refresh_token,
844
- isNewIdentity: true,
846
+ user: this.toUser(data.identity),
847
+ isNewIdentity: data.is_new_identity ?? false,
845
848
  authMethod: data.auth_method,
846
849
  oauthProvider: data.oauth_provider,
847
- identity: data.identity,
848
850
  };
849
851
  }
850
852
  // Multi-tenant selection required
@@ -2046,12 +2048,16 @@ class TenantLoginComponent {
2046
2048
  return;
2047
2049
  }
2048
2050
  // New identity — user exists but has no tenant membership
2049
- if (result.isNewIdentity && result.identity) {
2051
+ if (result.isNewIdentity && result.user) {
2050
2052
  this.needsOnboarding.emit({
2051
2053
  auth_method: result.authMethod || 'oauth',
2052
2054
  oauth_provider: result.oauthProvider,
2053
2055
  is_new_identity: true,
2054
- identity: result.identity,
2056
+ identity: {
2057
+ email: result.user.email,
2058
+ display_name: result.user.display_name,
2059
+ picture: result.user.photo_url,
2060
+ },
2055
2061
  });
2056
2062
  return;
2057
2063
  }