@riligar/auth-react 1.5.0 → 1.6.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 +87 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +87 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -274,6 +274,17 @@ const getSession = async () => {
|
|
|
274
274
|
return await api('/auth/session');
|
|
275
275
|
};
|
|
276
276
|
|
|
277
|
+
/*--- Application Info ----------------------------*/
|
|
278
|
+
const getApplicationInfo = async () => {
|
|
279
|
+
try {
|
|
280
|
+
const data = await api('/application/by-api-key');
|
|
281
|
+
return data?.data || null;
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.warn('[AuthSDK] Failed to fetch application info:', error.message);
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
277
288
|
/* Social login redirect (ex.: Google) -----------*/
|
|
278
289
|
function socialRedirect(provider, redirectTo = typeof window !== 'undefined' ? window.location.href : '/') {
|
|
279
290
|
if (typeof window === 'undefined') return;
|
|
@@ -337,6 +348,8 @@ const useAuthStore = create((set, get) => ({
|
|
|
337
348
|
verifyEmail: false,
|
|
338
349
|
resendVerification: false
|
|
339
350
|
},
|
|
351
|
+
// Application info (logo, nome, etc)
|
|
352
|
+
applicationInfo: null,
|
|
340
353
|
// Helper para atualizar loading states
|
|
341
354
|
setLoading: (key, value) => set(state => ({
|
|
342
355
|
loadingStates: {
|
|
@@ -344,9 +357,29 @@ const useAuthStore = create((set, get) => ({
|
|
|
344
357
|
[key]: value
|
|
345
358
|
}
|
|
346
359
|
})),
|
|
360
|
+
// Buscar informações da aplicação
|
|
361
|
+
fetchApplicationInfo: async () => {
|
|
362
|
+
try {
|
|
363
|
+
const appInfo = await getApplicationInfo();
|
|
364
|
+
set({
|
|
365
|
+
applicationInfo: appInfo
|
|
366
|
+
});
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.warn('[AuthStore] Failed to fetch application info:', error);
|
|
369
|
+
set({
|
|
370
|
+
applicationInfo: null
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
},
|
|
347
374
|
/* Init ao montar o Provider */
|
|
348
375
|
init: async () => {
|
|
376
|
+
const {
|
|
377
|
+
fetchApplicationInfo
|
|
378
|
+
} = get();
|
|
349
379
|
try {
|
|
380
|
+
// Buscar application info primeiro (não bloqueia o init)
|
|
381
|
+
fetchApplicationInfo();
|
|
382
|
+
|
|
350
383
|
// Verifica se há um token válido
|
|
351
384
|
if (isAuthenticated()) {
|
|
352
385
|
// Tenta extrair usuário do token (JWT)
|
|
@@ -865,6 +898,13 @@ const useSession = () => useAuthStore(useShallow(s => ({
|
|
|
865
898
|
// Loading States Hook
|
|
866
899
|
const useAuthLoading = () => useAuthStore(s => s.loadingStates);
|
|
867
900
|
|
|
901
|
+
// Application Logo Hook
|
|
902
|
+
const useApplicationLogo = () => {
|
|
903
|
+
const applicationInfo = useAuthStore(s => s.applicationInfo);
|
|
904
|
+
// Retorna o logo da aplicação ou null (componentes usam fallback padrão)
|
|
905
|
+
return applicationInfo?.image || null;
|
|
906
|
+
};
|
|
907
|
+
|
|
868
908
|
function ProtectedRoute({
|
|
869
909
|
fallback = /*#__PURE__*/React.createElement("p", null, "\u231B Carregando..."),
|
|
870
910
|
redirectTo = "/login"
|
|
@@ -900,7 +940,7 @@ function AuthCard({
|
|
|
900
940
|
title,
|
|
901
941
|
subtitle,
|
|
902
942
|
logo,
|
|
903
|
-
logoHeight =
|
|
943
|
+
logoHeight = 28,
|
|
904
944
|
width = 350,
|
|
905
945
|
...props
|
|
906
946
|
}) {
|
|
@@ -935,7 +975,8 @@ var img = "data:image/webp;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAADICAYAAADskzu8AA
|
|
|
935
975
|
*/
|
|
936
976
|
function SignInForm({
|
|
937
977
|
// Configuração
|
|
938
|
-
logo
|
|
978
|
+
logo,
|
|
979
|
+
// Removido default, será calculado abaixo
|
|
939
980
|
title = 'Entrar',
|
|
940
981
|
subtitle = 'Acesse sua conta para continuar',
|
|
941
982
|
// Features
|
|
@@ -961,6 +1002,10 @@ function SignInForm({
|
|
|
961
1002
|
const loadingSignIn = useAuthStore(s => s.loadingStates.signIn);
|
|
962
1003
|
const loadingMagicLink = useAuthStore(s => s.loadingStates.magicLink);
|
|
963
1004
|
const loadingResetPassword = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1005
|
+
|
|
1006
|
+
// Hook para buscar logo da aplicação
|
|
1007
|
+
const applicationLogo = useApplicationLogo();
|
|
1008
|
+
const finalLogo = logo || applicationLogo || img;
|
|
964
1009
|
const form$1 = form.useForm({
|
|
965
1010
|
initialValues: {
|
|
966
1011
|
email: '',
|
|
@@ -1005,7 +1050,7 @@ function SignInForm({
|
|
|
1005
1050
|
};
|
|
1006
1051
|
const isLoading = loadingSignIn || loadingMagicLink || loadingResetPassword;
|
|
1007
1052
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1008
|
-
logo:
|
|
1053
|
+
logo: finalLogo,
|
|
1009
1054
|
title: title,
|
|
1010
1055
|
subtitle: subtitle
|
|
1011
1056
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1083,7 +1128,7 @@ function SignInForm({
|
|
|
1083
1128
|
*/
|
|
1084
1129
|
function SignUpForm({
|
|
1085
1130
|
// Configuração
|
|
1086
|
-
logo
|
|
1131
|
+
logo,
|
|
1087
1132
|
title = 'Criar Conta',
|
|
1088
1133
|
subtitle = 'Preencha os dados para se cadastrar',
|
|
1089
1134
|
// Features
|
|
@@ -1102,6 +1147,10 @@ function SignUpForm({
|
|
|
1102
1147
|
}) {
|
|
1103
1148
|
const signUp = useAuthStore(s => s.signUp);
|
|
1104
1149
|
const loading = useAuthStore(s => s.loadingStates.signUp);
|
|
1150
|
+
|
|
1151
|
+
// Hook para buscar logo da aplicação
|
|
1152
|
+
const applicationLogo = useApplicationLogo();
|
|
1153
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1105
1154
|
const form$1 = form.useForm({
|
|
1106
1155
|
initialValues: {
|
|
1107
1156
|
name: '',
|
|
@@ -1125,7 +1174,7 @@ function SignUpForm({
|
|
|
1125
1174
|
}
|
|
1126
1175
|
};
|
|
1127
1176
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1128
|
-
logo:
|
|
1177
|
+
logo: finalLogo,
|
|
1129
1178
|
title: title,
|
|
1130
1179
|
subtitle: subtitle
|
|
1131
1180
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1202,7 +1251,7 @@ function SignUpForm({
|
|
|
1202
1251
|
*/
|
|
1203
1252
|
function MagicLinkForm({
|
|
1204
1253
|
// Configuração
|
|
1205
|
-
logo
|
|
1254
|
+
logo,
|
|
1206
1255
|
title = 'Login sem Senha',
|
|
1207
1256
|
subtitle = 'Receba um link de acesso no seu email',
|
|
1208
1257
|
// Features
|
|
@@ -1218,6 +1267,10 @@ function MagicLinkForm({
|
|
|
1218
1267
|
}) {
|
|
1219
1268
|
const sendMagicLink = useAuthStore(s => s.sendMagicLink);
|
|
1220
1269
|
const loading = useAuthStore(s => s.loadingStates.magicLink);
|
|
1270
|
+
|
|
1271
|
+
// Hook para buscar logo da aplicação
|
|
1272
|
+
const applicationLogo = useApplicationLogo();
|
|
1273
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1221
1274
|
const form$1 = form.useForm({
|
|
1222
1275
|
initialValues: {
|
|
1223
1276
|
email: ''
|
|
@@ -1235,7 +1288,7 @@ function MagicLinkForm({
|
|
|
1235
1288
|
}
|
|
1236
1289
|
};
|
|
1237
1290
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1238
|
-
logo:
|
|
1291
|
+
logo: finalLogo,
|
|
1239
1292
|
title: title,
|
|
1240
1293
|
subtitle: subtitle
|
|
1241
1294
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1271,7 +1324,7 @@ function MagicLinkForm({
|
|
|
1271
1324
|
*/
|
|
1272
1325
|
function MagicLinkVerify({
|
|
1273
1326
|
// Configuração
|
|
1274
|
-
logo
|
|
1327
|
+
logo,
|
|
1275
1328
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1276
1329
|
token: propToken,
|
|
1277
1330
|
// Callbacks
|
|
@@ -1287,6 +1340,10 @@ function MagicLinkVerify({
|
|
|
1287
1340
|
const [status, setStatus] = React$1.useState('verifying'); // verifying, success, error
|
|
1288
1341
|
const [errorMessage, setErrorMessage] = React$1.useState('');
|
|
1289
1342
|
const verifyMagicLink = useAuthStore(s => s.verifyMagicLink);
|
|
1343
|
+
|
|
1344
|
+
// Hook para buscar logo da aplicação
|
|
1345
|
+
const applicationLogo = useApplicationLogo();
|
|
1346
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1290
1347
|
const verifyingTokenRef = React$1.useRef(null);
|
|
1291
1348
|
React$1.useEffect(() => {
|
|
1292
1349
|
const verify = async () => {
|
|
@@ -1325,7 +1382,7 @@ function MagicLinkVerify({
|
|
|
1325
1382
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1326
1383
|
}, [propToken, redirectTo, redirectDelay]);
|
|
1327
1384
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1328
|
-
logo:
|
|
1385
|
+
logo: finalLogo
|
|
1329
1386
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(core.Stack, {
|
|
1330
1387
|
align: "center",
|
|
1331
1388
|
gap: "sm"
|
|
@@ -1369,7 +1426,7 @@ function MagicLinkVerify({
|
|
|
1369
1426
|
*/
|
|
1370
1427
|
function ForgotPasswordForm({
|
|
1371
1428
|
// Configuração
|
|
1372
|
-
logo
|
|
1429
|
+
logo,
|
|
1373
1430
|
title = 'Recuperar Senha',
|
|
1374
1431
|
subtitle = 'Enviaremos um link para redefinir sua senha',
|
|
1375
1432
|
// Features
|
|
@@ -1385,6 +1442,10 @@ function ForgotPasswordForm({
|
|
|
1385
1442
|
}) {
|
|
1386
1443
|
const forgotPassword = useAuthStore(s => s.forgotPassword);
|
|
1387
1444
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1445
|
+
|
|
1446
|
+
// Hook para buscar logo da aplicação
|
|
1447
|
+
const applicationLogo = useApplicationLogo();
|
|
1448
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1388
1449
|
const form$1 = form.useForm({
|
|
1389
1450
|
initialValues: {
|
|
1390
1451
|
email: ''
|
|
@@ -1402,7 +1463,7 @@ function ForgotPasswordForm({
|
|
|
1402
1463
|
}
|
|
1403
1464
|
};
|
|
1404
1465
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1405
|
-
logo:
|
|
1466
|
+
logo: finalLogo,
|
|
1406
1467
|
title: title,
|
|
1407
1468
|
subtitle: subtitle
|
|
1408
1469
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1437,7 +1498,7 @@ function ForgotPasswordForm({
|
|
|
1437
1498
|
*/
|
|
1438
1499
|
function ResetPasswordForm({
|
|
1439
1500
|
// Configuração
|
|
1440
|
-
logo
|
|
1501
|
+
logo,
|
|
1441
1502
|
title = 'Nova Senha',
|
|
1442
1503
|
subtitle = 'Crie uma nova senha para sua conta',
|
|
1443
1504
|
// Token pode ser passado diretamente ou extraído da URL
|
|
@@ -1456,6 +1517,10 @@ function ResetPasswordForm({
|
|
|
1456
1517
|
const resetPassword = useAuthStore(s => s.resetPassword);
|
|
1457
1518
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1458
1519
|
|
|
1520
|
+
// Hook para buscar logo da aplicação
|
|
1521
|
+
const applicationLogo = useApplicationLogo();
|
|
1522
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1523
|
+
|
|
1459
1524
|
// Extrai token da URL se não foi passado como prop
|
|
1460
1525
|
React$1.useEffect(() => {
|
|
1461
1526
|
if (!propToken && typeof window !== 'undefined') {
|
|
@@ -1489,7 +1554,7 @@ function ResetPasswordForm({
|
|
|
1489
1554
|
};
|
|
1490
1555
|
if (success) {
|
|
1491
1556
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1492
|
-
logo:
|
|
1557
|
+
logo: finalLogo
|
|
1493
1558
|
}, cardProps), /*#__PURE__*/React.createElement(core.Stack, {
|
|
1494
1559
|
align: "center",
|
|
1495
1560
|
gap: "sm"
|
|
@@ -1510,7 +1575,7 @@ function ResetPasswordForm({
|
|
|
1510
1575
|
}
|
|
1511
1576
|
if (!token) {
|
|
1512
1577
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1513
|
-
logo:
|
|
1578
|
+
logo: finalLogo
|
|
1514
1579
|
}, cardProps), /*#__PURE__*/React.createElement(core.Stack, {
|
|
1515
1580
|
align: "center",
|
|
1516
1581
|
gap: "sm"
|
|
@@ -1524,7 +1589,7 @@ function ResetPasswordForm({
|
|
|
1524
1589
|
}, labels.goToSignIn || 'Voltar para Login')));
|
|
1525
1590
|
}
|
|
1526
1591
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1527
|
-
logo:
|
|
1592
|
+
logo: finalLogo,
|
|
1528
1593
|
title: title,
|
|
1529
1594
|
subtitle: subtitle
|
|
1530
1595
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1560,7 +1625,7 @@ function ResetPasswordForm({
|
|
|
1560
1625
|
*/
|
|
1561
1626
|
function VerifyEmailCard({
|
|
1562
1627
|
// Configuração
|
|
1563
|
-
logo
|
|
1628
|
+
logo,
|
|
1564
1629
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1565
1630
|
token: propToken,
|
|
1566
1631
|
// Email para reenvio (opcional)
|
|
@@ -1585,6 +1650,10 @@ function VerifyEmailCard({
|
|
|
1585
1650
|
const loadingResend = useAuthStore(s => s.loadingStates.resendVerification);
|
|
1586
1651
|
const user = useAuthStore(s => s.user);
|
|
1587
1652
|
const verifyingTokenRef = React$1.useRef(null);
|
|
1653
|
+
|
|
1654
|
+
// Hook para buscar logo da aplicação
|
|
1655
|
+
const applicationLogo = useApplicationLogo();
|
|
1656
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1588
1657
|
React$1.useEffect(() => {
|
|
1589
1658
|
const verify = async () => {
|
|
1590
1659
|
// Pega token da prop ou da URL
|
|
@@ -1644,7 +1713,7 @@ function VerifyEmailCard({
|
|
|
1644
1713
|
}
|
|
1645
1714
|
};
|
|
1646
1715
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1647
|
-
logo:
|
|
1716
|
+
logo: finalLogo
|
|
1648
1717
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(core.Stack, {
|
|
1649
1718
|
align: "center",
|
|
1650
1719
|
gap: "sm"
|
|
@@ -1716,6 +1785,7 @@ exports.VerifyEmailCard = VerifyEmailCard;
|
|
|
1716
1785
|
exports.configure = configure;
|
|
1717
1786
|
exports.decodeJWT = decodeJWT;
|
|
1718
1787
|
exports.forgotPassword = forgotPassword;
|
|
1788
|
+
exports.getApplicationInfo = getApplicationInfo;
|
|
1719
1789
|
exports.getCurrentUser = getCurrentUser;
|
|
1720
1790
|
exports.getSession = getSession;
|
|
1721
1791
|
exports.isAuthenticated = isAuthenticated;
|