@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.esm.js +19 -90
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +19 -90
- package/dist/index.js.map +1 -1
- package/package.json +1 -5
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';
|
|
@@ -422,7 +421,8 @@ const useAuthStore = create((set, get) => ({
|
|
|
422
421
|
});
|
|
423
422
|
try {
|
|
424
423
|
const result = await signUp(email, password, name);
|
|
425
|
-
|
|
424
|
+
// Usa o user completo da resposta da API
|
|
425
|
+
const user = result.user || null;
|
|
426
426
|
set({
|
|
427
427
|
user,
|
|
428
428
|
loading: false
|
|
@@ -448,10 +448,10 @@ const useAuthStore = create((set, get) => ({
|
|
|
448
448
|
try {
|
|
449
449
|
const result = await signIn(email, password);
|
|
450
450
|
|
|
451
|
-
//
|
|
452
|
-
let user =
|
|
451
|
+
// Usa o user completo da resposta da API (já contém email, name, image, etc)
|
|
452
|
+
let user = result.user || null;
|
|
453
453
|
|
|
454
|
-
// Se não
|
|
454
|
+
// Se não veio user na resposta, tenta buscar da sessão
|
|
455
455
|
if (!user) {
|
|
456
456
|
const sessionData = await getSession();
|
|
457
457
|
if (sessionData?.user) user = sessionData.user;
|
|
@@ -2073,6 +2073,8 @@ function UserProfile({
|
|
|
2073
2073
|
onProfileUpdate,
|
|
2074
2074
|
onPasswordChange,
|
|
2075
2075
|
onEmailChange,
|
|
2076
|
+
onSessionRevoked,
|
|
2077
|
+
onOtherSessionsRevoked,
|
|
2076
2078
|
onError,
|
|
2077
2079
|
// Features toggle
|
|
2078
2080
|
showAvatar = true,
|
|
@@ -2159,7 +2161,9 @@ function UserProfile({
|
|
|
2159
2161
|
if (isCurrentSession) {
|
|
2160
2162
|
try {
|
|
2161
2163
|
await revokeSession(sessionId);
|
|
2164
|
+
onSessionRevoked?.(sessionId);
|
|
2162
2165
|
} catch (error) {
|
|
2166
|
+
onError?.(error);
|
|
2163
2167
|
// Even if it fails, we're revoking our own session, so just logout
|
|
2164
2168
|
// The server already revoked our session
|
|
2165
2169
|
}
|
|
@@ -2173,11 +2177,7 @@ function UserProfile({
|
|
|
2173
2177
|
// Revoking another session
|
|
2174
2178
|
try {
|
|
2175
2179
|
await revokeSession(sessionId);
|
|
2176
|
-
|
|
2177
|
-
title: labels.successTitle || 'Sucesso',
|
|
2178
|
-
message: labels.sessionRevoked || 'Sessão encerrada com sucesso',
|
|
2179
|
-
color: 'green'
|
|
2180
|
-
});
|
|
2180
|
+
onSessionRevoked?.(sessionId);
|
|
2181
2181
|
} catch (error) {
|
|
2182
2182
|
// Check for 401 error (our SDK uses error.res, axios uses error.response)
|
|
2183
2183
|
const status = error.res?.status || error.response?.status;
|
|
@@ -2188,28 +2188,14 @@ function UserProfile({
|
|
|
2188
2188
|
if (variant === 'modal') onClose?.();
|
|
2189
2189
|
return;
|
|
2190
2190
|
}
|
|
2191
|
-
notifications.show({
|
|
2192
|
-
title: labels.errorTitle || 'Erro',
|
|
2193
|
-
message: error.message || labels.sessionRevokeFailed || 'Falha ao encerrar sessão',
|
|
2194
|
-
color: 'red'
|
|
2195
|
-
});
|
|
2196
2191
|
onError?.(error);
|
|
2197
2192
|
}
|
|
2198
2193
|
};
|
|
2199
2194
|
const handleRevokeOtherSessions = async () => {
|
|
2200
2195
|
try {
|
|
2201
2196
|
await revokeOtherSessions();
|
|
2202
|
-
|
|
2203
|
-
title: labels.successTitle || 'Sucesso',
|
|
2204
|
-
message: labels.otherSessionsRevoked || 'Todas as outras sessões foram encerradas',
|
|
2205
|
-
color: 'green'
|
|
2206
|
-
});
|
|
2197
|
+
onOtherSessionsRevoked?.();
|
|
2207
2198
|
} 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
2199
|
onError?.(error);
|
|
2214
2200
|
}
|
|
2215
2201
|
};
|
|
@@ -2270,21 +2256,13 @@ function UserProfile({
|
|
|
2270
2256
|
|
|
2271
2257
|
// Validate file type
|
|
2272
2258
|
if (!file.type.startsWith('image/')) {
|
|
2273
|
-
|
|
2274
|
-
title: labels.errorTitle || 'Erro',
|
|
2275
|
-
message: labels.avatarInvalidType || 'Por favor, selecione uma imagem válida',
|
|
2276
|
-
color: 'red'
|
|
2277
|
-
});
|
|
2259
|
+
onError?.(new Error(labels.avatarInvalidType || 'Por favor, selecione uma imagem válida'));
|
|
2278
2260
|
return;
|
|
2279
2261
|
}
|
|
2280
2262
|
|
|
2281
2263
|
// Validate file size
|
|
2282
2264
|
if (file.size > maxAvatarSize) {
|
|
2283
|
-
|
|
2284
|
-
title: labels.errorTitle || 'Erro',
|
|
2285
|
-
message: labels.avatarTooLarge || `Imagem muito grande. Máximo ${Math.round(maxAvatarSize / 1024)}KB.`,
|
|
2286
|
-
color: 'red'
|
|
2287
|
-
});
|
|
2265
|
+
onError?.(new Error(labels.avatarTooLarge || `Imagem muito grande. Máximo ${Math.round(maxAvatarSize / 1024)}KB.`));
|
|
2288
2266
|
return;
|
|
2289
2267
|
}
|
|
2290
2268
|
setAvatarFile(file);
|
|
@@ -2323,40 +2301,20 @@ function UserProfile({
|
|
|
2323
2301
|
const handleChangePassword = async values => {
|
|
2324
2302
|
try {
|
|
2325
2303
|
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
2304
|
passwordForm.reset();
|
|
2332
2305
|
setEditingSection(null);
|
|
2333
2306
|
onPasswordChange?.();
|
|
2334
2307
|
} 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
2308
|
onError?.(error);
|
|
2341
2309
|
}
|
|
2342
2310
|
};
|
|
2343
2311
|
const handleChangeEmail = async values => {
|
|
2344
2312
|
try {
|
|
2345
2313
|
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
2314
|
emailForm.reset();
|
|
2352
2315
|
setEditingSection(null);
|
|
2353
2316
|
onEmailChange?.(values.newEmail);
|
|
2354
2317
|
} 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
2318
|
onError?.(error);
|
|
2361
2319
|
}
|
|
2362
2320
|
};
|
|
@@ -2365,43 +2323,29 @@ function UserProfile({
|
|
|
2365
2323
|
await updateProfile({
|
|
2366
2324
|
name: values.name
|
|
2367
2325
|
});
|
|
2368
|
-
notifications.show({
|
|
2369
|
-
title: labels.successTitle || 'Sucesso',
|
|
2370
|
-
message: labels.nameUpdated || 'Nome atualizado com sucesso',
|
|
2371
|
-
color: 'green'
|
|
2372
|
-
});
|
|
2373
2326
|
nameForm.reset();
|
|
2374
2327
|
setEditingSection(null);
|
|
2375
2328
|
onProfileUpdate?.({
|
|
2376
2329
|
name: values.name
|
|
2377
2330
|
});
|
|
2378
2331
|
} 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
2332
|
onError?.(error);
|
|
2385
2333
|
}
|
|
2386
2334
|
};
|
|
2387
2335
|
const handleChangeAvatar = async () => {
|
|
2388
2336
|
if (!avatarPreview) {
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2337
|
+
// Optionally handle this validation error via callback or just return?
|
|
2338
|
+
// Since it's a validation error before async call, we might want to expose it too?
|
|
2339
|
+
// The original code used notifications. Let's send to onError for consistency or just return if it's UI state.
|
|
2340
|
+
// Actually, for validation within the component, maybe we can just let it be silent or use form error if applicable?
|
|
2341
|
+
// But this is outside form context. Let's use onError with a custom error object.
|
|
2342
|
+
onError?.(new Error(labels.avatarRequired || 'Selecione uma imagem'));
|
|
2394
2343
|
return;
|
|
2395
2344
|
}
|
|
2396
2345
|
try {
|
|
2397
2346
|
await updateProfile({
|
|
2398
2347
|
image: avatarPreview
|
|
2399
2348
|
});
|
|
2400
|
-
notifications.show({
|
|
2401
|
-
title: labels.successTitle || 'Sucesso',
|
|
2402
|
-
message: labels.avatarUpdated || 'Foto de perfil atualizada com sucesso',
|
|
2403
|
-
color: 'green'
|
|
2404
|
-
});
|
|
2405
2349
|
setAvatarPreview(null);
|
|
2406
2350
|
setAvatarFile(null);
|
|
2407
2351
|
setEditingSection(null);
|
|
@@ -2409,11 +2353,6 @@ function UserProfile({
|
|
|
2409
2353
|
image: avatarPreview
|
|
2410
2354
|
});
|
|
2411
2355
|
} 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
2356
|
onError?.(error);
|
|
2418
2357
|
}
|
|
2419
2358
|
};
|
|
@@ -2422,11 +2361,6 @@ function UserProfile({
|
|
|
2422
2361
|
await updateProfile({
|
|
2423
2362
|
image: ''
|
|
2424
2363
|
});
|
|
2425
|
-
notifications.show({
|
|
2426
|
-
title: labels.successTitle || 'Sucesso',
|
|
2427
|
-
message: labels.avatarRemoved || 'Foto de perfil removida',
|
|
2428
|
-
color: 'green'
|
|
2429
|
-
});
|
|
2430
2364
|
setAvatarPreview(null);
|
|
2431
2365
|
setAvatarFile(null);
|
|
2432
2366
|
setEditingSection(null);
|
|
@@ -2434,11 +2368,6 @@ function UserProfile({
|
|
|
2434
2368
|
image: ''
|
|
2435
2369
|
});
|
|
2436
2370
|
} 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
2371
|
onError?.(error);
|
|
2443
2372
|
}
|
|
2444
2373
|
};
|