@riligar/auth-react 1.23.0 → 1.24.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.esm.js CHANGED
@@ -6,7 +6,6 @@ import { Navigate, Outlet, useNavigate } from 'react-router-dom';
6
6
  import { Modal, Stack, Text, Image, Title, Paper, TextInput, PasswordInput, Anchor, Button, Divider, Group, Center, Loader, Box, Avatar, Collapse, Card, Tooltip, ThemeIcon, Badge } from '@mantine/core';
7
7
  import { useForm } from '@mantine/form';
8
8
  import { IconMail, IconLock, IconArrowRight, IconBrandGoogle, IconBrandGithub, IconUser, IconSend, IconCheck, IconX, IconRefresh, IconPhoto, IconTrash, IconPencil, IconShield, IconKey, IconDevices, IconDeviceMobile, IconLogout, IconUserCircle } from '@tabler/icons-react';
9
- import { notifications } from '@mantine/notifications';
10
9
 
11
10
  // Config - API Base URL fixa para o serviço de autenticação
12
11
  let API_BASE = 'https://manager.myauth.click';
@@ -2073,6 +2072,8 @@ function UserProfile({
2073
2072
  onProfileUpdate,
2074
2073
  onPasswordChange,
2075
2074
  onEmailChange,
2075
+ onSessionRevoked,
2076
+ onOtherSessionsRevoked,
2076
2077
  onError,
2077
2078
  // Features toggle
2078
2079
  showAvatar = true,
@@ -2159,7 +2160,9 @@ function UserProfile({
2159
2160
  if (isCurrentSession) {
2160
2161
  try {
2161
2162
  await revokeSession(sessionId);
2163
+ onSessionRevoked?.(sessionId);
2162
2164
  } catch (error) {
2165
+ onError?.(error);
2163
2166
  // Even if it fails, we're revoking our own session, so just logout
2164
2167
  // The server already revoked our session
2165
2168
  }
@@ -2173,11 +2176,7 @@ function UserProfile({
2173
2176
  // Revoking another session
2174
2177
  try {
2175
2178
  await revokeSession(sessionId);
2176
- notifications.show({
2177
- title: labels.successTitle || 'Sucesso',
2178
- message: labels.sessionRevoked || 'Sessão encerrada com sucesso',
2179
- color: 'green'
2180
- });
2179
+ onSessionRevoked?.(sessionId);
2181
2180
  } catch (error) {
2182
2181
  // Check for 401 error (our SDK uses error.res, axios uses error.response)
2183
2182
  const status = error.res?.status || error.response?.status;
@@ -2188,28 +2187,14 @@ function UserProfile({
2188
2187
  if (variant === 'modal') onClose?.();
2189
2188
  return;
2190
2189
  }
2191
- notifications.show({
2192
- title: labels.errorTitle || 'Erro',
2193
- message: error.message || labels.sessionRevokeFailed || 'Falha ao encerrar sessão',
2194
- color: 'red'
2195
- });
2196
2190
  onError?.(error);
2197
2191
  }
2198
2192
  };
2199
2193
  const handleRevokeOtherSessions = async () => {
2200
2194
  try {
2201
2195
  await revokeOtherSessions();
2202
- notifications.show({
2203
- title: labels.successTitle || 'Sucesso',
2204
- message: labels.otherSessionsRevoked || 'Todas as outras sessões foram encerradas',
2205
- color: 'green'
2206
- });
2196
+ onOtherSessionsRevoked?.();
2207
2197
  } catch (error) {
2208
- notifications.show({
2209
- title: labels.errorTitle || 'Erro',
2210
- message: error.message || labels.otherSessionsRevokeFailed || 'Falha ao encerrar sessões',
2211
- color: 'red'
2212
- });
2213
2198
  onError?.(error);
2214
2199
  }
2215
2200
  };
@@ -2270,21 +2255,13 @@ function UserProfile({
2270
2255
 
2271
2256
  // Validate file type
2272
2257
  if (!file.type.startsWith('image/')) {
2273
- notifications.show({
2274
- title: labels.errorTitle || 'Erro',
2275
- message: labels.avatarInvalidType || 'Por favor, selecione uma imagem válida',
2276
- color: 'red'
2277
- });
2258
+ onError?.(new Error(labels.avatarInvalidType || 'Por favor, selecione uma imagem válida'));
2278
2259
  return;
2279
2260
  }
2280
2261
 
2281
2262
  // Validate file size
2282
2263
  if (file.size > maxAvatarSize) {
2283
- notifications.show({
2284
- title: labels.errorTitle || 'Erro',
2285
- message: labels.avatarTooLarge || `Imagem muito grande. Máximo ${Math.round(maxAvatarSize / 1024)}KB.`,
2286
- color: 'red'
2287
- });
2264
+ onError?.(new Error(labels.avatarTooLarge || `Imagem muito grande. Máximo ${Math.round(maxAvatarSize / 1024)}KB.`));
2288
2265
  return;
2289
2266
  }
2290
2267
  setAvatarFile(file);
@@ -2323,40 +2300,20 @@ function UserProfile({
2323
2300
  const handleChangePassword = async values => {
2324
2301
  try {
2325
2302
  await changePassword(values.currentPassword, values.newPassword);
2326
- notifications.show({
2327
- title: labels.successTitle || 'Sucesso',
2328
- message: labels.passwordChanged || 'Senha alterada com sucesso',
2329
- color: 'green'
2330
- });
2331
2303
  passwordForm.reset();
2332
2304
  setEditingSection(null);
2333
2305
  onPasswordChange?.();
2334
2306
  } catch (error) {
2335
- notifications.show({
2336
- title: labels.errorTitle || 'Erro',
2337
- message: error.message || labels.passwordChangeFailed || 'Falha ao alterar senha',
2338
- color: 'red'
2339
- });
2340
2307
  onError?.(error);
2341
2308
  }
2342
2309
  };
2343
2310
  const handleChangeEmail = async values => {
2344
2311
  try {
2345
2312
  await changeEmail(values.newEmail);
2346
- notifications.show({
2347
- title: labels.successTitle || 'Sucesso',
2348
- message: labels.emailVerificationSent || 'Verifique seu novo email para confirmar a alteração',
2349
- color: 'green'
2350
- });
2351
2313
  emailForm.reset();
2352
2314
  setEditingSection(null);
2353
2315
  onEmailChange?.(values.newEmail);
2354
2316
  } catch (error) {
2355
- notifications.show({
2356
- title: labels.errorTitle || 'Erro',
2357
- message: error.message || labels.emailChangeFailed || 'Falha ao alterar email',
2358
- color: 'red'
2359
- });
2360
2317
  onError?.(error);
2361
2318
  }
2362
2319
  };
@@ -2365,43 +2322,29 @@ function UserProfile({
2365
2322
  await updateProfile({
2366
2323
  name: values.name
2367
2324
  });
2368
- notifications.show({
2369
- title: labels.successTitle || 'Sucesso',
2370
- message: labels.nameUpdated || 'Nome atualizado com sucesso',
2371
- color: 'green'
2372
- });
2373
2325
  nameForm.reset();
2374
2326
  setEditingSection(null);
2375
2327
  onProfileUpdate?.({
2376
2328
  name: values.name
2377
2329
  });
2378
2330
  } catch (error) {
2379
- notifications.show({
2380
- title: labels.errorTitle || 'Erro',
2381
- message: error.message || labels.nameUpdateFailed || 'Falha ao atualizar nome',
2382
- color: 'red'
2383
- });
2384
2331
  onError?.(error);
2385
2332
  }
2386
2333
  };
2387
2334
  const handleChangeAvatar = async () => {
2388
2335
  if (!avatarPreview) {
2389
- notifications.show({
2390
- title: labels.errorTitle || 'Erro',
2391
- message: labels.avatarRequired || 'Selecione uma imagem',
2392
- color: 'red'
2393
- });
2336
+ // Optionally handle this validation error via callback or just return?
2337
+ // Since it's a validation error before async call, we might want to expose it too?
2338
+ // The original code used notifications. Let's send to onError for consistency or just return if it's UI state.
2339
+ // Actually, for validation within the component, maybe we can just let it be silent or use form error if applicable?
2340
+ // But this is outside form context. Let's use onError with a custom error object.
2341
+ onError?.(new Error(labels.avatarRequired || 'Selecione uma imagem'));
2394
2342
  return;
2395
2343
  }
2396
2344
  try {
2397
2345
  await updateProfile({
2398
2346
  image: avatarPreview
2399
2347
  });
2400
- notifications.show({
2401
- title: labels.successTitle || 'Sucesso',
2402
- message: labels.avatarUpdated || 'Foto de perfil atualizada com sucesso',
2403
- color: 'green'
2404
- });
2405
2348
  setAvatarPreview(null);
2406
2349
  setAvatarFile(null);
2407
2350
  setEditingSection(null);
@@ -2409,11 +2352,6 @@ function UserProfile({
2409
2352
  image: avatarPreview
2410
2353
  });
2411
2354
  } catch (error) {
2412
- notifications.show({
2413
- title: labels.errorTitle || 'Erro',
2414
- message: error.message || labels.avatarUpdateFailed || 'Falha ao atualizar foto',
2415
- color: 'red'
2416
- });
2417
2355
  onError?.(error);
2418
2356
  }
2419
2357
  };
@@ -2422,11 +2360,6 @@ function UserProfile({
2422
2360
  await updateProfile({
2423
2361
  image: ''
2424
2362
  });
2425
- notifications.show({
2426
- title: labels.successTitle || 'Sucesso',
2427
- message: labels.avatarRemoved || 'Foto de perfil removida',
2428
- color: 'green'
2429
- });
2430
2363
  setAvatarPreview(null);
2431
2364
  setAvatarFile(null);
2432
2365
  setEditingSection(null);
@@ -2434,11 +2367,6 @@ function UserProfile({
2434
2367
  image: ''
2435
2368
  });
2436
2369
  } catch (error) {
2437
- notifications.show({
2438
- title: labels.errorTitle || 'Erro',
2439
- message: error.message || labels.avatarRemoveFailed || 'Falha ao remover foto',
2440
- color: 'red'
2441
- });
2442
2370
  onError?.(error);
2443
2371
  }
2444
2372
  };