@imtbl/auth 2.12.5 → 2.12.6-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/src/types.ts CHANGED
@@ -26,10 +26,12 @@ export enum EvmChain {
26
26
  }
27
27
 
28
28
  export type ChainAddress = {
29
- ethAddress: string;
30
- userAdminAddress: string;
29
+ ethAddress: `0x${string}`;
30
+ userAdminAddress: `0x${string}`;
31
31
  };
32
32
 
33
+ export type ZkEvmInfo = ChainAddress;
34
+
33
35
  export type User = {
34
36
  idToken?: string;
35
37
  accessToken: string;
@@ -163,12 +165,44 @@ export type LoginOptions = {
163
165
  export enum AuthEvents {
164
166
  LOGGED_OUT = 'loggedOut',
165
167
  LOGGED_IN = 'loggedIn',
168
+ /**
169
+ * Emitted when tokens are refreshed via signinSilent().
170
+ * This is critical for refresh token rotation - when client-side refresh happens,
171
+ * the new tokens must be synced to server-side session to prevent race conditions.
172
+ */
173
+ TOKEN_REFRESHED = 'tokenRefreshed',
174
+ /**
175
+ * Emitted when the user is removed from local storage due to a permanent auth error.
176
+ * Only emitted for errors where the refresh token is truly invalid:
177
+ * - invalid_grant: refresh token expired, revoked, or already used
178
+ * - login_required: user must re-authenticate
179
+ * - consent_required / interaction_required: user must interact with auth server
180
+ *
181
+ * NOT emitted for transient errors (network, timeout, server errors) - user stays logged in.
182
+ * Consumers should sync this state by clearing their session (e.g., NextAuth signOut).
183
+ */
184
+ USER_REMOVED = 'userRemoved',
166
185
  }
167
186
 
187
+ /**
188
+ * Error reason for USER_REMOVED event.
189
+ * Note: Network/timeout errors do NOT emit USER_REMOVED (user stays logged in),
190
+ * so 'network_error' is not a valid reason.
191
+ */
192
+ export type UserRemovedReason =
193
+ // OAuth permanent errors (invalid_grant, login_required, etc.)
194
+ | 'refresh_token_invalid'
195
+ // Unknown non-OAuth errors
196
+ | 'refresh_failed'
197
+ // Fallback for truly unknown error types
198
+ | 'unknown';
199
+
168
200
  /**
169
201
  * Event map for typed event emitter
170
202
  */
171
203
  export interface AuthEventMap extends Record<string, any> {
172
204
  [AuthEvents.LOGGED_OUT]: [];
173
205
  [AuthEvents.LOGGED_IN]: [User];
206
+ [AuthEvents.TOKEN_REFRESHED]: [User];
207
+ [AuthEvents.USER_REMOVED]: [{ reason: UserRemovedReason; error?: string }];
174
208
  }