@riligar/auth-react 1.5.0 → 1.6.1
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 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +87 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -151,10 +151,6 @@ function isTokenExpired(token) {
|
|
|
151
151
|
function isAuthenticated() {
|
|
152
152
|
const token = getStoredToken();
|
|
153
153
|
const valid = token && !isTokenExpired(token);
|
|
154
|
-
console.log('[AuthSDK] isAuthenticated check:', {
|
|
155
|
-
hasToken: !!token,
|
|
156
|
-
valid
|
|
157
|
-
});
|
|
158
154
|
return valid;
|
|
159
155
|
}
|
|
160
156
|
|
|
@@ -274,6 +270,17 @@ const getSession = async () => {
|
|
|
274
270
|
return await api('/auth/session');
|
|
275
271
|
};
|
|
276
272
|
|
|
273
|
+
/*--- Application Info ----------------------------*/
|
|
274
|
+
const getApplicationInfo = async () => {
|
|
275
|
+
try {
|
|
276
|
+
const data = await api('/application/by-api-key');
|
|
277
|
+
return data?.data || null;
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.warn('[AuthSDK] Failed to fetch application info:', error.message);
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
277
284
|
/* Social login redirect (ex.: Google) -----------*/
|
|
278
285
|
function socialRedirect(provider, redirectTo = typeof window !== 'undefined' ? window.location.href : '/') {
|
|
279
286
|
if (typeof window === 'undefined') return;
|
|
@@ -337,6 +344,8 @@ const useAuthStore = create((set, get) => ({
|
|
|
337
344
|
verifyEmail: false,
|
|
338
345
|
resendVerification: false
|
|
339
346
|
},
|
|
347
|
+
// Application info (logo, nome, etc)
|
|
348
|
+
applicationInfo: null,
|
|
340
349
|
// Helper para atualizar loading states
|
|
341
350
|
setLoading: (key, value) => set(state => ({
|
|
342
351
|
loadingStates: {
|
|
@@ -344,9 +353,29 @@ const useAuthStore = create((set, get) => ({
|
|
|
344
353
|
[key]: value
|
|
345
354
|
}
|
|
346
355
|
})),
|
|
356
|
+
// Buscar informações da aplicação
|
|
357
|
+
fetchApplicationInfo: async () => {
|
|
358
|
+
try {
|
|
359
|
+
const appInfo = await getApplicationInfo();
|
|
360
|
+
set({
|
|
361
|
+
applicationInfo: appInfo
|
|
362
|
+
});
|
|
363
|
+
} catch (error) {
|
|
364
|
+
console.warn('[AuthStore] Failed to fetch application info:', error);
|
|
365
|
+
set({
|
|
366
|
+
applicationInfo: null
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
},
|
|
347
370
|
/* Init ao montar o Provider */
|
|
348
371
|
init: async () => {
|
|
372
|
+
const {
|
|
373
|
+
fetchApplicationInfo
|
|
374
|
+
} = get();
|
|
349
375
|
try {
|
|
376
|
+
// Buscar application info primeiro (não bloqueia o init)
|
|
377
|
+
fetchApplicationInfo();
|
|
378
|
+
|
|
350
379
|
// Verifica se há um token válido
|
|
351
380
|
if (isAuthenticated()) {
|
|
352
381
|
// Tenta extrair usuário do token (JWT)
|
|
@@ -865,6 +894,13 @@ const useSession = () => useAuthStore(useShallow(s => ({
|
|
|
865
894
|
// Loading States Hook
|
|
866
895
|
const useAuthLoading = () => useAuthStore(s => s.loadingStates);
|
|
867
896
|
|
|
897
|
+
// Application Logo Hook
|
|
898
|
+
const useApplicationLogo = () => {
|
|
899
|
+
const applicationInfo = useAuthStore(s => s.applicationInfo);
|
|
900
|
+
// Retorna o logo da aplicação ou null (componentes usam fallback padrão)
|
|
901
|
+
return applicationInfo?.image || null;
|
|
902
|
+
};
|
|
903
|
+
|
|
868
904
|
function ProtectedRoute({
|
|
869
905
|
fallback = /*#__PURE__*/React.createElement("p", null, "\u231B Carregando..."),
|
|
870
906
|
redirectTo = "/login"
|
|
@@ -900,7 +936,7 @@ function AuthCard({
|
|
|
900
936
|
title,
|
|
901
937
|
subtitle,
|
|
902
938
|
logo,
|
|
903
|
-
logoHeight =
|
|
939
|
+
logoHeight = 28,
|
|
904
940
|
width = 350,
|
|
905
941
|
...props
|
|
906
942
|
}) {
|
|
@@ -935,7 +971,8 @@ var img = "data:image/webp;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAADICAYAAADskzu8AA
|
|
|
935
971
|
*/
|
|
936
972
|
function SignInForm({
|
|
937
973
|
// Configuração
|
|
938
|
-
logo
|
|
974
|
+
logo,
|
|
975
|
+
// Removido default, será calculado abaixo
|
|
939
976
|
title = 'Entrar',
|
|
940
977
|
subtitle = 'Acesse sua conta para continuar',
|
|
941
978
|
// Features
|
|
@@ -961,6 +998,10 @@ function SignInForm({
|
|
|
961
998
|
const loadingSignIn = useAuthStore(s => s.loadingStates.signIn);
|
|
962
999
|
const loadingMagicLink = useAuthStore(s => s.loadingStates.magicLink);
|
|
963
1000
|
const loadingResetPassword = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1001
|
+
|
|
1002
|
+
// Hook para buscar logo da aplicação
|
|
1003
|
+
const applicationLogo = useApplicationLogo();
|
|
1004
|
+
const finalLogo = logo || applicationLogo || img;
|
|
964
1005
|
const form$1 = form.useForm({
|
|
965
1006
|
initialValues: {
|
|
966
1007
|
email: '',
|
|
@@ -1005,7 +1046,7 @@ function SignInForm({
|
|
|
1005
1046
|
};
|
|
1006
1047
|
const isLoading = loadingSignIn || loadingMagicLink || loadingResetPassword;
|
|
1007
1048
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1008
|
-
logo:
|
|
1049
|
+
logo: finalLogo,
|
|
1009
1050
|
title: title,
|
|
1010
1051
|
subtitle: subtitle
|
|
1011
1052
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1083,7 +1124,7 @@ function SignInForm({
|
|
|
1083
1124
|
*/
|
|
1084
1125
|
function SignUpForm({
|
|
1085
1126
|
// Configuração
|
|
1086
|
-
logo
|
|
1127
|
+
logo,
|
|
1087
1128
|
title = 'Criar Conta',
|
|
1088
1129
|
subtitle = 'Preencha os dados para se cadastrar',
|
|
1089
1130
|
// Features
|
|
@@ -1102,6 +1143,10 @@ function SignUpForm({
|
|
|
1102
1143
|
}) {
|
|
1103
1144
|
const signUp = useAuthStore(s => s.signUp);
|
|
1104
1145
|
const loading = useAuthStore(s => s.loadingStates.signUp);
|
|
1146
|
+
|
|
1147
|
+
// Hook para buscar logo da aplicação
|
|
1148
|
+
const applicationLogo = useApplicationLogo();
|
|
1149
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1105
1150
|
const form$1 = form.useForm({
|
|
1106
1151
|
initialValues: {
|
|
1107
1152
|
name: '',
|
|
@@ -1125,7 +1170,7 @@ function SignUpForm({
|
|
|
1125
1170
|
}
|
|
1126
1171
|
};
|
|
1127
1172
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1128
|
-
logo:
|
|
1173
|
+
logo: finalLogo,
|
|
1129
1174
|
title: title,
|
|
1130
1175
|
subtitle: subtitle
|
|
1131
1176
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1202,7 +1247,7 @@ function SignUpForm({
|
|
|
1202
1247
|
*/
|
|
1203
1248
|
function MagicLinkForm({
|
|
1204
1249
|
// Configuração
|
|
1205
|
-
logo
|
|
1250
|
+
logo,
|
|
1206
1251
|
title = 'Login sem Senha',
|
|
1207
1252
|
subtitle = 'Receba um link de acesso no seu email',
|
|
1208
1253
|
// Features
|
|
@@ -1218,6 +1263,10 @@ function MagicLinkForm({
|
|
|
1218
1263
|
}) {
|
|
1219
1264
|
const sendMagicLink = useAuthStore(s => s.sendMagicLink);
|
|
1220
1265
|
const loading = useAuthStore(s => s.loadingStates.magicLink);
|
|
1266
|
+
|
|
1267
|
+
// Hook para buscar logo da aplicação
|
|
1268
|
+
const applicationLogo = useApplicationLogo();
|
|
1269
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1221
1270
|
const form$1 = form.useForm({
|
|
1222
1271
|
initialValues: {
|
|
1223
1272
|
email: ''
|
|
@@ -1235,7 +1284,7 @@ function MagicLinkForm({
|
|
|
1235
1284
|
}
|
|
1236
1285
|
};
|
|
1237
1286
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1238
|
-
logo:
|
|
1287
|
+
logo: finalLogo,
|
|
1239
1288
|
title: title,
|
|
1240
1289
|
subtitle: subtitle
|
|
1241
1290
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1271,7 +1320,7 @@ function MagicLinkForm({
|
|
|
1271
1320
|
*/
|
|
1272
1321
|
function MagicLinkVerify({
|
|
1273
1322
|
// Configuração
|
|
1274
|
-
logo
|
|
1323
|
+
logo,
|
|
1275
1324
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1276
1325
|
token: propToken,
|
|
1277
1326
|
// Callbacks
|
|
@@ -1287,6 +1336,10 @@ function MagicLinkVerify({
|
|
|
1287
1336
|
const [status, setStatus] = React$1.useState('verifying'); // verifying, success, error
|
|
1288
1337
|
const [errorMessage, setErrorMessage] = React$1.useState('');
|
|
1289
1338
|
const verifyMagicLink = useAuthStore(s => s.verifyMagicLink);
|
|
1339
|
+
|
|
1340
|
+
// Hook para buscar logo da aplicação
|
|
1341
|
+
const applicationLogo = useApplicationLogo();
|
|
1342
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1290
1343
|
const verifyingTokenRef = React$1.useRef(null);
|
|
1291
1344
|
React$1.useEffect(() => {
|
|
1292
1345
|
const verify = async () => {
|
|
@@ -1325,7 +1378,7 @@ function MagicLinkVerify({
|
|
|
1325
1378
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1326
1379
|
}, [propToken, redirectTo, redirectDelay]);
|
|
1327
1380
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1328
|
-
logo:
|
|
1381
|
+
logo: finalLogo
|
|
1329
1382
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(core.Stack, {
|
|
1330
1383
|
align: "center",
|
|
1331
1384
|
gap: "sm"
|
|
@@ -1369,7 +1422,7 @@ function MagicLinkVerify({
|
|
|
1369
1422
|
*/
|
|
1370
1423
|
function ForgotPasswordForm({
|
|
1371
1424
|
// Configuração
|
|
1372
|
-
logo
|
|
1425
|
+
logo,
|
|
1373
1426
|
title = 'Recuperar Senha',
|
|
1374
1427
|
subtitle = 'Enviaremos um link para redefinir sua senha',
|
|
1375
1428
|
// Features
|
|
@@ -1385,6 +1438,10 @@ function ForgotPasswordForm({
|
|
|
1385
1438
|
}) {
|
|
1386
1439
|
const forgotPassword = useAuthStore(s => s.forgotPassword);
|
|
1387
1440
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1441
|
+
|
|
1442
|
+
// Hook para buscar logo da aplicação
|
|
1443
|
+
const applicationLogo = useApplicationLogo();
|
|
1444
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1388
1445
|
const form$1 = form.useForm({
|
|
1389
1446
|
initialValues: {
|
|
1390
1447
|
email: ''
|
|
@@ -1402,7 +1459,7 @@ function ForgotPasswordForm({
|
|
|
1402
1459
|
}
|
|
1403
1460
|
};
|
|
1404
1461
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1405
|
-
logo:
|
|
1462
|
+
logo: finalLogo,
|
|
1406
1463
|
title: title,
|
|
1407
1464
|
subtitle: subtitle
|
|
1408
1465
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1437,7 +1494,7 @@ function ForgotPasswordForm({
|
|
|
1437
1494
|
*/
|
|
1438
1495
|
function ResetPasswordForm({
|
|
1439
1496
|
// Configuração
|
|
1440
|
-
logo
|
|
1497
|
+
logo,
|
|
1441
1498
|
title = 'Nova Senha',
|
|
1442
1499
|
subtitle = 'Crie uma nova senha para sua conta',
|
|
1443
1500
|
// Token pode ser passado diretamente ou extraído da URL
|
|
@@ -1456,6 +1513,10 @@ function ResetPasswordForm({
|
|
|
1456
1513
|
const resetPassword = useAuthStore(s => s.resetPassword);
|
|
1457
1514
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1458
1515
|
|
|
1516
|
+
// Hook para buscar logo da aplicação
|
|
1517
|
+
const applicationLogo = useApplicationLogo();
|
|
1518
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1519
|
+
|
|
1459
1520
|
// Extrai token da URL se não foi passado como prop
|
|
1460
1521
|
React$1.useEffect(() => {
|
|
1461
1522
|
if (!propToken && typeof window !== 'undefined') {
|
|
@@ -1489,7 +1550,7 @@ function ResetPasswordForm({
|
|
|
1489
1550
|
};
|
|
1490
1551
|
if (success) {
|
|
1491
1552
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1492
|
-
logo:
|
|
1553
|
+
logo: finalLogo
|
|
1493
1554
|
}, cardProps), /*#__PURE__*/React.createElement(core.Stack, {
|
|
1494
1555
|
align: "center",
|
|
1495
1556
|
gap: "sm"
|
|
@@ -1510,7 +1571,7 @@ function ResetPasswordForm({
|
|
|
1510
1571
|
}
|
|
1511
1572
|
if (!token) {
|
|
1512
1573
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1513
|
-
logo:
|
|
1574
|
+
logo: finalLogo
|
|
1514
1575
|
}, cardProps), /*#__PURE__*/React.createElement(core.Stack, {
|
|
1515
1576
|
align: "center",
|
|
1516
1577
|
gap: "sm"
|
|
@@ -1524,7 +1585,7 @@ function ResetPasswordForm({
|
|
|
1524
1585
|
}, labels.goToSignIn || 'Voltar para Login')));
|
|
1525
1586
|
}
|
|
1526
1587
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1527
|
-
logo:
|
|
1588
|
+
logo: finalLogo,
|
|
1528
1589
|
title: title,
|
|
1529
1590
|
subtitle: subtitle
|
|
1530
1591
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1560,7 +1621,7 @@ function ResetPasswordForm({
|
|
|
1560
1621
|
*/
|
|
1561
1622
|
function VerifyEmailCard({
|
|
1562
1623
|
// Configuração
|
|
1563
|
-
logo
|
|
1624
|
+
logo,
|
|
1564
1625
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1565
1626
|
token: propToken,
|
|
1566
1627
|
// Email para reenvio (opcional)
|
|
@@ -1585,6 +1646,10 @@ function VerifyEmailCard({
|
|
|
1585
1646
|
const loadingResend = useAuthStore(s => s.loadingStates.resendVerification);
|
|
1586
1647
|
const user = useAuthStore(s => s.user);
|
|
1587
1648
|
const verifyingTokenRef = React$1.useRef(null);
|
|
1649
|
+
|
|
1650
|
+
// Hook para buscar logo da aplicação
|
|
1651
|
+
const applicationLogo = useApplicationLogo();
|
|
1652
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1588
1653
|
React$1.useEffect(() => {
|
|
1589
1654
|
const verify = async () => {
|
|
1590
1655
|
// Pega token da prop ou da URL
|
|
@@ -1644,7 +1709,7 @@ function VerifyEmailCard({
|
|
|
1644
1709
|
}
|
|
1645
1710
|
};
|
|
1646
1711
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1647
|
-
logo:
|
|
1712
|
+
logo: finalLogo
|
|
1648
1713
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(core.Stack, {
|
|
1649
1714
|
align: "center",
|
|
1650
1715
|
gap: "sm"
|
|
@@ -1716,6 +1781,7 @@ exports.VerifyEmailCard = VerifyEmailCard;
|
|
|
1716
1781
|
exports.configure = configure;
|
|
1717
1782
|
exports.decodeJWT = decodeJWT;
|
|
1718
1783
|
exports.forgotPassword = forgotPassword;
|
|
1784
|
+
exports.getApplicationInfo = getApplicationInfo;
|
|
1719
1785
|
exports.getCurrentUser = getCurrentUser;
|
|
1720
1786
|
exports.getSession = getSession;
|
|
1721
1787
|
exports.isAuthenticated = isAuthenticated;
|