@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.esm.js
CHANGED
|
@@ -271,6 +271,17 @@ const getSession = async () => {
|
|
|
271
271
|
return await api('/auth/session');
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
+
/*--- Application Info ----------------------------*/
|
|
275
|
+
const getApplicationInfo = async () => {
|
|
276
|
+
try {
|
|
277
|
+
const data = await api('/application/by-api-key');
|
|
278
|
+
return data?.data || null;
|
|
279
|
+
} catch (error) {
|
|
280
|
+
console.warn('[AuthSDK] Failed to fetch application info:', error.message);
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
274
285
|
/* Social login redirect (ex.: Google) -----------*/
|
|
275
286
|
function socialRedirect(provider, redirectTo = typeof window !== 'undefined' ? window.location.href : '/') {
|
|
276
287
|
if (typeof window === 'undefined') return;
|
|
@@ -334,6 +345,8 @@ const useAuthStore = create((set, get) => ({
|
|
|
334
345
|
verifyEmail: false,
|
|
335
346
|
resendVerification: false
|
|
336
347
|
},
|
|
348
|
+
// Application info (logo, nome, etc)
|
|
349
|
+
applicationInfo: null,
|
|
337
350
|
// Helper para atualizar loading states
|
|
338
351
|
setLoading: (key, value) => set(state => ({
|
|
339
352
|
loadingStates: {
|
|
@@ -341,9 +354,29 @@ const useAuthStore = create((set, get) => ({
|
|
|
341
354
|
[key]: value
|
|
342
355
|
}
|
|
343
356
|
})),
|
|
357
|
+
// Buscar informações da aplicação
|
|
358
|
+
fetchApplicationInfo: async () => {
|
|
359
|
+
try {
|
|
360
|
+
const appInfo = await getApplicationInfo();
|
|
361
|
+
set({
|
|
362
|
+
applicationInfo: appInfo
|
|
363
|
+
});
|
|
364
|
+
} catch (error) {
|
|
365
|
+
console.warn('[AuthStore] Failed to fetch application info:', error);
|
|
366
|
+
set({
|
|
367
|
+
applicationInfo: null
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
},
|
|
344
371
|
/* Init ao montar o Provider */
|
|
345
372
|
init: async () => {
|
|
373
|
+
const {
|
|
374
|
+
fetchApplicationInfo
|
|
375
|
+
} = get();
|
|
346
376
|
try {
|
|
377
|
+
// Buscar application info primeiro (não bloqueia o init)
|
|
378
|
+
fetchApplicationInfo();
|
|
379
|
+
|
|
347
380
|
// Verifica se há um token válido
|
|
348
381
|
if (isAuthenticated()) {
|
|
349
382
|
// Tenta extrair usuário do token (JWT)
|
|
@@ -862,6 +895,13 @@ const useSession = () => useAuthStore(useShallow(s => ({
|
|
|
862
895
|
// Loading States Hook
|
|
863
896
|
const useAuthLoading = () => useAuthStore(s => s.loadingStates);
|
|
864
897
|
|
|
898
|
+
// Application Logo Hook
|
|
899
|
+
const useApplicationLogo = () => {
|
|
900
|
+
const applicationInfo = useAuthStore(s => s.applicationInfo);
|
|
901
|
+
// Retorna o logo da aplicação ou null (componentes usam fallback padrão)
|
|
902
|
+
return applicationInfo?.image || null;
|
|
903
|
+
};
|
|
904
|
+
|
|
865
905
|
function ProtectedRoute({
|
|
866
906
|
fallback = /*#__PURE__*/React.createElement("p", null, "\u231B Carregando..."),
|
|
867
907
|
redirectTo = "/login"
|
|
@@ -897,7 +937,7 @@ function AuthCard({
|
|
|
897
937
|
title,
|
|
898
938
|
subtitle,
|
|
899
939
|
logo,
|
|
900
|
-
logoHeight =
|
|
940
|
+
logoHeight = 28,
|
|
901
941
|
width = 350,
|
|
902
942
|
...props
|
|
903
943
|
}) {
|
|
@@ -932,7 +972,8 @@ var img = "data:image/webp;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAADICAYAAADskzu8AA
|
|
|
932
972
|
*/
|
|
933
973
|
function SignInForm({
|
|
934
974
|
// Configuração
|
|
935
|
-
logo
|
|
975
|
+
logo,
|
|
976
|
+
// Removido default, será calculado abaixo
|
|
936
977
|
title = 'Entrar',
|
|
937
978
|
subtitle = 'Acesse sua conta para continuar',
|
|
938
979
|
// Features
|
|
@@ -958,6 +999,10 @@ function SignInForm({
|
|
|
958
999
|
const loadingSignIn = useAuthStore(s => s.loadingStates.signIn);
|
|
959
1000
|
const loadingMagicLink = useAuthStore(s => s.loadingStates.magicLink);
|
|
960
1001
|
const loadingResetPassword = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1002
|
+
|
|
1003
|
+
// Hook para buscar logo da aplicação
|
|
1004
|
+
const applicationLogo = useApplicationLogo();
|
|
1005
|
+
const finalLogo = logo || applicationLogo || img;
|
|
961
1006
|
const form = useForm({
|
|
962
1007
|
initialValues: {
|
|
963
1008
|
email: '',
|
|
@@ -1002,7 +1047,7 @@ function SignInForm({
|
|
|
1002
1047
|
};
|
|
1003
1048
|
const isLoading = loadingSignIn || loadingMagicLink || loadingResetPassword;
|
|
1004
1049
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1005
|
-
logo:
|
|
1050
|
+
logo: finalLogo,
|
|
1006
1051
|
title: title,
|
|
1007
1052
|
subtitle: subtitle
|
|
1008
1053
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1080,7 +1125,7 @@ function SignInForm({
|
|
|
1080
1125
|
*/
|
|
1081
1126
|
function SignUpForm({
|
|
1082
1127
|
// Configuração
|
|
1083
|
-
logo
|
|
1128
|
+
logo,
|
|
1084
1129
|
title = 'Criar Conta',
|
|
1085
1130
|
subtitle = 'Preencha os dados para se cadastrar',
|
|
1086
1131
|
// Features
|
|
@@ -1099,6 +1144,10 @@ function SignUpForm({
|
|
|
1099
1144
|
}) {
|
|
1100
1145
|
const signUp = useAuthStore(s => s.signUp);
|
|
1101
1146
|
const loading = useAuthStore(s => s.loadingStates.signUp);
|
|
1147
|
+
|
|
1148
|
+
// Hook para buscar logo da aplicação
|
|
1149
|
+
const applicationLogo = useApplicationLogo();
|
|
1150
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1102
1151
|
const form = useForm({
|
|
1103
1152
|
initialValues: {
|
|
1104
1153
|
name: '',
|
|
@@ -1122,7 +1171,7 @@ function SignUpForm({
|
|
|
1122
1171
|
}
|
|
1123
1172
|
};
|
|
1124
1173
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1125
|
-
logo:
|
|
1174
|
+
logo: finalLogo,
|
|
1126
1175
|
title: title,
|
|
1127
1176
|
subtitle: subtitle
|
|
1128
1177
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1199,7 +1248,7 @@ function SignUpForm({
|
|
|
1199
1248
|
*/
|
|
1200
1249
|
function MagicLinkForm({
|
|
1201
1250
|
// Configuração
|
|
1202
|
-
logo
|
|
1251
|
+
logo,
|
|
1203
1252
|
title = 'Login sem Senha',
|
|
1204
1253
|
subtitle = 'Receba um link de acesso no seu email',
|
|
1205
1254
|
// Features
|
|
@@ -1215,6 +1264,10 @@ function MagicLinkForm({
|
|
|
1215
1264
|
}) {
|
|
1216
1265
|
const sendMagicLink = useAuthStore(s => s.sendMagicLink);
|
|
1217
1266
|
const loading = useAuthStore(s => s.loadingStates.magicLink);
|
|
1267
|
+
|
|
1268
|
+
// Hook para buscar logo da aplicação
|
|
1269
|
+
const applicationLogo = useApplicationLogo();
|
|
1270
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1218
1271
|
const form = useForm({
|
|
1219
1272
|
initialValues: {
|
|
1220
1273
|
email: ''
|
|
@@ -1232,7 +1285,7 @@ function MagicLinkForm({
|
|
|
1232
1285
|
}
|
|
1233
1286
|
};
|
|
1234
1287
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1235
|
-
logo:
|
|
1288
|
+
logo: finalLogo,
|
|
1236
1289
|
title: title,
|
|
1237
1290
|
subtitle: subtitle
|
|
1238
1291
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1268,7 +1321,7 @@ function MagicLinkForm({
|
|
|
1268
1321
|
*/
|
|
1269
1322
|
function MagicLinkVerify({
|
|
1270
1323
|
// Configuração
|
|
1271
|
-
logo
|
|
1324
|
+
logo,
|
|
1272
1325
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1273
1326
|
token: propToken,
|
|
1274
1327
|
// Callbacks
|
|
@@ -1284,6 +1337,10 @@ function MagicLinkVerify({
|
|
|
1284
1337
|
const [status, setStatus] = useState('verifying'); // verifying, success, error
|
|
1285
1338
|
const [errorMessage, setErrorMessage] = useState('');
|
|
1286
1339
|
const verifyMagicLink = useAuthStore(s => s.verifyMagicLink);
|
|
1340
|
+
|
|
1341
|
+
// Hook para buscar logo da aplicação
|
|
1342
|
+
const applicationLogo = useApplicationLogo();
|
|
1343
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1287
1344
|
const verifyingTokenRef = useRef(null);
|
|
1288
1345
|
useEffect(() => {
|
|
1289
1346
|
const verify = async () => {
|
|
@@ -1322,7 +1379,7 @@ function MagicLinkVerify({
|
|
|
1322
1379
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1323
1380
|
}, [propToken, redirectTo, redirectDelay]);
|
|
1324
1381
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1325
|
-
logo:
|
|
1382
|
+
logo: finalLogo
|
|
1326
1383
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(Stack, {
|
|
1327
1384
|
align: "center",
|
|
1328
1385
|
gap: "sm"
|
|
@@ -1366,7 +1423,7 @@ function MagicLinkVerify({
|
|
|
1366
1423
|
*/
|
|
1367
1424
|
function ForgotPasswordForm({
|
|
1368
1425
|
// Configuração
|
|
1369
|
-
logo
|
|
1426
|
+
logo,
|
|
1370
1427
|
title = 'Recuperar Senha',
|
|
1371
1428
|
subtitle = 'Enviaremos um link para redefinir sua senha',
|
|
1372
1429
|
// Features
|
|
@@ -1382,6 +1439,10 @@ function ForgotPasswordForm({
|
|
|
1382
1439
|
}) {
|
|
1383
1440
|
const forgotPassword = useAuthStore(s => s.forgotPassword);
|
|
1384
1441
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1442
|
+
|
|
1443
|
+
// Hook para buscar logo da aplicação
|
|
1444
|
+
const applicationLogo = useApplicationLogo();
|
|
1445
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1385
1446
|
const form = useForm({
|
|
1386
1447
|
initialValues: {
|
|
1387
1448
|
email: ''
|
|
@@ -1399,7 +1460,7 @@ function ForgotPasswordForm({
|
|
|
1399
1460
|
}
|
|
1400
1461
|
};
|
|
1401
1462
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1402
|
-
logo:
|
|
1463
|
+
logo: finalLogo,
|
|
1403
1464
|
title: title,
|
|
1404
1465
|
subtitle: subtitle
|
|
1405
1466
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1434,7 +1495,7 @@ function ForgotPasswordForm({
|
|
|
1434
1495
|
*/
|
|
1435
1496
|
function ResetPasswordForm({
|
|
1436
1497
|
// Configuração
|
|
1437
|
-
logo
|
|
1498
|
+
logo,
|
|
1438
1499
|
title = 'Nova Senha',
|
|
1439
1500
|
subtitle = 'Crie uma nova senha para sua conta',
|
|
1440
1501
|
// Token pode ser passado diretamente ou extraído da URL
|
|
@@ -1453,6 +1514,10 @@ function ResetPasswordForm({
|
|
|
1453
1514
|
const resetPassword = useAuthStore(s => s.resetPassword);
|
|
1454
1515
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1455
1516
|
|
|
1517
|
+
// Hook para buscar logo da aplicação
|
|
1518
|
+
const applicationLogo = useApplicationLogo();
|
|
1519
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1520
|
+
|
|
1456
1521
|
// Extrai token da URL se não foi passado como prop
|
|
1457
1522
|
useEffect(() => {
|
|
1458
1523
|
if (!propToken && typeof window !== 'undefined') {
|
|
@@ -1486,7 +1551,7 @@ function ResetPasswordForm({
|
|
|
1486
1551
|
};
|
|
1487
1552
|
if (success) {
|
|
1488
1553
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1489
|
-
logo:
|
|
1554
|
+
logo: finalLogo
|
|
1490
1555
|
}, cardProps), /*#__PURE__*/React.createElement(Stack, {
|
|
1491
1556
|
align: "center",
|
|
1492
1557
|
gap: "sm"
|
|
@@ -1507,7 +1572,7 @@ function ResetPasswordForm({
|
|
|
1507
1572
|
}
|
|
1508
1573
|
if (!token) {
|
|
1509
1574
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1510
|
-
logo:
|
|
1575
|
+
logo: finalLogo
|
|
1511
1576
|
}, cardProps), /*#__PURE__*/React.createElement(Stack, {
|
|
1512
1577
|
align: "center",
|
|
1513
1578
|
gap: "sm"
|
|
@@ -1521,7 +1586,7 @@ function ResetPasswordForm({
|
|
|
1521
1586
|
}, labels.goToSignIn || 'Voltar para Login')));
|
|
1522
1587
|
}
|
|
1523
1588
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1524
|
-
logo:
|
|
1589
|
+
logo: finalLogo,
|
|
1525
1590
|
title: title,
|
|
1526
1591
|
subtitle: subtitle
|
|
1527
1592
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1557,7 +1622,7 @@ function ResetPasswordForm({
|
|
|
1557
1622
|
*/
|
|
1558
1623
|
function VerifyEmailCard({
|
|
1559
1624
|
// Configuração
|
|
1560
|
-
logo
|
|
1625
|
+
logo,
|
|
1561
1626
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1562
1627
|
token: propToken,
|
|
1563
1628
|
// Email para reenvio (opcional)
|
|
@@ -1582,6 +1647,10 @@ function VerifyEmailCard({
|
|
|
1582
1647
|
const loadingResend = useAuthStore(s => s.loadingStates.resendVerification);
|
|
1583
1648
|
const user = useAuthStore(s => s.user);
|
|
1584
1649
|
const verifyingTokenRef = useRef(null);
|
|
1650
|
+
|
|
1651
|
+
// Hook para buscar logo da aplicação
|
|
1652
|
+
const applicationLogo = useApplicationLogo();
|
|
1653
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1585
1654
|
useEffect(() => {
|
|
1586
1655
|
const verify = async () => {
|
|
1587
1656
|
// Pega token da prop ou da URL
|
|
@@ -1641,7 +1710,7 @@ function VerifyEmailCard({
|
|
|
1641
1710
|
}
|
|
1642
1711
|
};
|
|
1643
1712
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1644
|
-
logo:
|
|
1713
|
+
logo: finalLogo
|
|
1645
1714
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(Stack, {
|
|
1646
1715
|
align: "center",
|
|
1647
1716
|
gap: "sm"
|
|
@@ -1700,5 +1769,5 @@ function VerifyEmailCard({
|
|
|
1700
1769
|
}, labels.resend || 'Solicitar novo link')));
|
|
1701
1770
|
}
|
|
1702
1771
|
|
|
1703
|
-
export { AuthCard, AuthProvider, ForgotPasswordForm, MagicLinkForm, MagicLinkVerify, ProtectedRoute, ResetPasswordForm, SignInForm, SignUpForm, VerifyEmailCard, configure, decodeJWT, forgotPassword, getCurrentUser, getSession, isAuthenticated, refreshToken, resendVerification, resetPassword, sendMagicLink, signIn, signOut, signUp, socialRedirect, useAuth, useAuthLoading, useAuthStore, useCheckToken, useEmailVerification, useMagicLink, usePasswordReset, useSession, useSignIn, useSignOut, useSignUp, verifyEmail, verifyMagicLink };
|
|
1772
|
+
export { AuthCard, AuthProvider, ForgotPasswordForm, MagicLinkForm, MagicLinkVerify, ProtectedRoute, ResetPasswordForm, SignInForm, SignUpForm, VerifyEmailCard, configure, decodeJWT, forgotPassword, getApplicationInfo, getCurrentUser, getSession, isAuthenticated, refreshToken, resendVerification, resetPassword, sendMagicLink, signIn, signOut, signUp, socialRedirect, useAuth, useAuthLoading, useAuthStore, useCheckToken, useEmailVerification, useMagicLink, usePasswordReset, useSession, useSignIn, useSignOut, useSignUp, verifyEmail, verifyMagicLink };
|
|
1704
1773
|
//# sourceMappingURL=index.esm.js.map
|