@riligar/auth-react 1.23.0 → 1.25.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/dist/index.js CHANGED
@@ -8,7 +8,6 @@ var reactRouterDom = require('react-router-dom');
8
8
  var core = require('@mantine/core');
9
9
  var form = require('@mantine/form');
10
10
  var iconsReact = require('@tabler/icons-react');
11
- var notifications = require('@mantine/notifications');
12
11
 
13
12
  // Config - API Base URL fixa para o serviço de autenticação
14
13
  let API_BASE = 'https://manager.myauth.click';
@@ -424,7 +423,8 @@ const useAuthStore = zustand.create((set, get) => ({
424
423
  });
425
424
  try {
426
425
  const result = await signUp(email, password, name);
427
- const user = getCurrentUser();
426
+ // Usa o user completo da resposta da API
427
+ const user = result.user || null;
428
428
  set({
429
429
  user,
430
430
  loading: false
@@ -450,10 +450,10 @@ const useAuthStore = zustand.create((set, get) => ({
450
450
  try {
451
451
  const result = await signIn(email, password);
452
452
 
453
- // Tenta obter usuário do token (se JWT)
454
- let user = getCurrentUser();
453
+ // Usa o user completo da resposta da API ( contém email, name, image, etc)
454
+ let user = result.user || null;
455
455
 
456
- // Se não encontrou no token (sessão opaca), busca do servidor
456
+ // Se não veio user na resposta, tenta buscar da sessão
457
457
  if (!user) {
458
458
  const sessionData = await getSession();
459
459
  if (sessionData?.user) user = sessionData.user;
@@ -2075,6 +2075,8 @@ function UserProfile({
2075
2075
  onProfileUpdate,
2076
2076
  onPasswordChange,
2077
2077
  onEmailChange,
2078
+ onSessionRevoked,
2079
+ onOtherSessionsRevoked,
2078
2080
  onError,
2079
2081
  // Features toggle
2080
2082
  showAvatar = true,
@@ -2161,7 +2163,9 @@ function UserProfile({
2161
2163
  if (isCurrentSession) {
2162
2164
  try {
2163
2165
  await revokeSession(sessionId);
2166
+ onSessionRevoked?.(sessionId);
2164
2167
  } catch (error) {
2168
+ onError?.(error);
2165
2169
  // Even if it fails, we're revoking our own session, so just logout
2166
2170
  // The server already revoked our session
2167
2171
  }
@@ -2175,11 +2179,7 @@ function UserProfile({
2175
2179
  // Revoking another session
2176
2180
  try {
2177
2181
  await revokeSession(sessionId);
2178
- notifications.notifications.show({
2179
- title: labels.successTitle || 'Sucesso',
2180
- message: labels.sessionRevoked || 'Sessão encerrada com sucesso',
2181
- color: 'green'
2182
- });
2182
+ onSessionRevoked?.(sessionId);
2183
2183
  } catch (error) {
2184
2184
  // Check for 401 error (our SDK uses error.res, axios uses error.response)
2185
2185
  const status = error.res?.status || error.response?.status;
@@ -2190,28 +2190,14 @@ function UserProfile({
2190
2190
  if (variant === 'modal') onClose?.();
2191
2191
  return;
2192
2192
  }
2193
- notifications.notifications.show({
2194
- title: labels.errorTitle || 'Erro',
2195
- message: error.message || labels.sessionRevokeFailed || 'Falha ao encerrar sessão',
2196
- color: 'red'
2197
- });
2198
2193
  onError?.(error);
2199
2194
  }
2200
2195
  };
2201
2196
  const handleRevokeOtherSessions = async () => {
2202
2197
  try {
2203
2198
  await revokeOtherSessions();
2204
- notifications.notifications.show({
2205
- title: labels.successTitle || 'Sucesso',
2206
- message: labels.otherSessionsRevoked || 'Todas as outras sessões foram encerradas',
2207
- color: 'green'
2208
- });
2199
+ onOtherSessionsRevoked?.();
2209
2200
  } catch (error) {
2210
- notifications.notifications.show({
2211
- title: labels.errorTitle || 'Erro',
2212
- message: error.message || labels.otherSessionsRevokeFailed || 'Falha ao encerrar sessões',
2213
- color: 'red'
2214
- });
2215
2201
  onError?.(error);
2216
2202
  }
2217
2203
  };
@@ -2272,21 +2258,13 @@ function UserProfile({
2272
2258
 
2273
2259
  // Validate file type
2274
2260
  if (!file.type.startsWith('image/')) {
2275
- notifications.notifications.show({
2276
- title: labels.errorTitle || 'Erro',
2277
- message: labels.avatarInvalidType || 'Por favor, selecione uma imagem válida',
2278
- color: 'red'
2279
- });
2261
+ onError?.(new Error(labels.avatarInvalidType || 'Por favor, selecione uma imagem válida'));
2280
2262
  return;
2281
2263
  }
2282
2264
 
2283
2265
  // Validate file size
2284
2266
  if (file.size > maxAvatarSize) {
2285
- notifications.notifications.show({
2286
- title: labels.errorTitle || 'Erro',
2287
- message: labels.avatarTooLarge || `Imagem muito grande. Máximo ${Math.round(maxAvatarSize / 1024)}KB.`,
2288
- color: 'red'
2289
- });
2267
+ onError?.(new Error(labels.avatarTooLarge || `Imagem muito grande. Máximo ${Math.round(maxAvatarSize / 1024)}KB.`));
2290
2268
  return;
2291
2269
  }
2292
2270
  setAvatarFile(file);
@@ -2325,40 +2303,20 @@ function UserProfile({
2325
2303
  const handleChangePassword = async values => {
2326
2304
  try {
2327
2305
  await changePassword(values.currentPassword, values.newPassword);
2328
- notifications.notifications.show({
2329
- title: labels.successTitle || 'Sucesso',
2330
- message: labels.passwordChanged || 'Senha alterada com sucesso',
2331
- color: 'green'
2332
- });
2333
2306
  passwordForm.reset();
2334
2307
  setEditingSection(null);
2335
2308
  onPasswordChange?.();
2336
2309
  } catch (error) {
2337
- notifications.notifications.show({
2338
- title: labels.errorTitle || 'Erro',
2339
- message: error.message || labels.passwordChangeFailed || 'Falha ao alterar senha',
2340
- color: 'red'
2341
- });
2342
2310
  onError?.(error);
2343
2311
  }
2344
2312
  };
2345
2313
  const handleChangeEmail = async values => {
2346
2314
  try {
2347
2315
  await changeEmail(values.newEmail);
2348
- notifications.notifications.show({
2349
- title: labels.successTitle || 'Sucesso',
2350
- message: labels.emailVerificationSent || 'Verifique seu novo email para confirmar a alteração',
2351
- color: 'green'
2352
- });
2353
2316
  emailForm.reset();
2354
2317
  setEditingSection(null);
2355
2318
  onEmailChange?.(values.newEmail);
2356
2319
  } catch (error) {
2357
- notifications.notifications.show({
2358
- title: labels.errorTitle || 'Erro',
2359
- message: error.message || labels.emailChangeFailed || 'Falha ao alterar email',
2360
- color: 'red'
2361
- });
2362
2320
  onError?.(error);
2363
2321
  }
2364
2322
  };
@@ -2367,43 +2325,29 @@ function UserProfile({
2367
2325
  await updateProfile({
2368
2326
  name: values.name
2369
2327
  });
2370
- notifications.notifications.show({
2371
- title: labels.successTitle || 'Sucesso',
2372
- message: labels.nameUpdated || 'Nome atualizado com sucesso',
2373
- color: 'green'
2374
- });
2375
2328
  nameForm.reset();
2376
2329
  setEditingSection(null);
2377
2330
  onProfileUpdate?.({
2378
2331
  name: values.name
2379
2332
  });
2380
2333
  } catch (error) {
2381
- notifications.notifications.show({
2382
- title: labels.errorTitle || 'Erro',
2383
- message: error.message || labels.nameUpdateFailed || 'Falha ao atualizar nome',
2384
- color: 'red'
2385
- });
2386
2334
  onError?.(error);
2387
2335
  }
2388
2336
  };
2389
2337
  const handleChangeAvatar = async () => {
2390
2338
  if (!avatarPreview) {
2391
- notifications.notifications.show({
2392
- title: labels.errorTitle || 'Erro',
2393
- message: labels.avatarRequired || 'Selecione uma imagem',
2394
- color: 'red'
2395
- });
2339
+ // Optionally handle this validation error via callback or just return?
2340
+ // Since it's a validation error before async call, we might want to expose it too?
2341
+ // The original code used notifications. Let's send to onError for consistency or just return if it's UI state.
2342
+ // Actually, for validation within the component, maybe we can just let it be silent or use form error if applicable?
2343
+ // But this is outside form context. Let's use onError with a custom error object.
2344
+ onError?.(new Error(labels.avatarRequired || 'Selecione uma imagem'));
2396
2345
  return;
2397
2346
  }
2398
2347
  try {
2399
2348
  await updateProfile({
2400
2349
  image: avatarPreview
2401
2350
  });
2402
- notifications.notifications.show({
2403
- title: labels.successTitle || 'Sucesso',
2404
- message: labels.avatarUpdated || 'Foto de perfil atualizada com sucesso',
2405
- color: 'green'
2406
- });
2407
2351
  setAvatarPreview(null);
2408
2352
  setAvatarFile(null);
2409
2353
  setEditingSection(null);
@@ -2411,11 +2355,6 @@ function UserProfile({
2411
2355
  image: avatarPreview
2412
2356
  });
2413
2357
  } catch (error) {
2414
- notifications.notifications.show({
2415
- title: labels.errorTitle || 'Erro',
2416
- message: error.message || labels.avatarUpdateFailed || 'Falha ao atualizar foto',
2417
- color: 'red'
2418
- });
2419
2358
  onError?.(error);
2420
2359
  }
2421
2360
  };
@@ -2424,11 +2363,6 @@ function UserProfile({
2424
2363
  await updateProfile({
2425
2364
  image: ''
2426
2365
  });
2427
- notifications.notifications.show({
2428
- title: labels.successTitle || 'Sucesso',
2429
- message: labels.avatarRemoved || 'Foto de perfil removida',
2430
- color: 'green'
2431
- });
2432
2366
  setAvatarPreview(null);
2433
2367
  setAvatarFile(null);
2434
2368
  setEditingSection(null);
@@ -2436,11 +2370,6 @@ function UserProfile({
2436
2370
  image: ''
2437
2371
  });
2438
2372
  } catch (error) {
2439
- notifications.notifications.show({
2440
- title: labels.errorTitle || 'Erro',
2441
- message: error.message || labels.avatarRemoveFailed || 'Falha ao remover foto',
2442
- color: 'red'
2443
- });
2444
2373
  onError?.(error);
2445
2374
  }
2446
2375
  };