@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.esm.js
CHANGED
|
@@ -148,10 +148,6 @@ function isTokenExpired(token) {
|
|
|
148
148
|
function isAuthenticated() {
|
|
149
149
|
const token = getStoredToken();
|
|
150
150
|
const valid = token && !isTokenExpired(token);
|
|
151
|
-
console.log('[AuthSDK] isAuthenticated check:', {
|
|
152
|
-
hasToken: !!token,
|
|
153
|
-
valid
|
|
154
|
-
});
|
|
155
151
|
return valid;
|
|
156
152
|
}
|
|
157
153
|
|
|
@@ -271,6 +267,17 @@ const getSession = async () => {
|
|
|
271
267
|
return await api('/auth/session');
|
|
272
268
|
};
|
|
273
269
|
|
|
270
|
+
/*--- Application Info ----------------------------*/
|
|
271
|
+
const getApplicationInfo = async () => {
|
|
272
|
+
try {
|
|
273
|
+
const data = await api('/application/by-api-key');
|
|
274
|
+
return data?.data || null;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.warn('[AuthSDK] Failed to fetch application info:', error.message);
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
274
281
|
/* Social login redirect (ex.: Google) -----------*/
|
|
275
282
|
function socialRedirect(provider, redirectTo = typeof window !== 'undefined' ? window.location.href : '/') {
|
|
276
283
|
if (typeof window === 'undefined') return;
|
|
@@ -334,6 +341,8 @@ const useAuthStore = create((set, get) => ({
|
|
|
334
341
|
verifyEmail: false,
|
|
335
342
|
resendVerification: false
|
|
336
343
|
},
|
|
344
|
+
// Application info (logo, nome, etc)
|
|
345
|
+
applicationInfo: null,
|
|
337
346
|
// Helper para atualizar loading states
|
|
338
347
|
setLoading: (key, value) => set(state => ({
|
|
339
348
|
loadingStates: {
|
|
@@ -341,9 +350,29 @@ const useAuthStore = create((set, get) => ({
|
|
|
341
350
|
[key]: value
|
|
342
351
|
}
|
|
343
352
|
})),
|
|
353
|
+
// Buscar informações da aplicação
|
|
354
|
+
fetchApplicationInfo: async () => {
|
|
355
|
+
try {
|
|
356
|
+
const appInfo = await getApplicationInfo();
|
|
357
|
+
set({
|
|
358
|
+
applicationInfo: appInfo
|
|
359
|
+
});
|
|
360
|
+
} catch (error) {
|
|
361
|
+
console.warn('[AuthStore] Failed to fetch application info:', error);
|
|
362
|
+
set({
|
|
363
|
+
applicationInfo: null
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
},
|
|
344
367
|
/* Init ao montar o Provider */
|
|
345
368
|
init: async () => {
|
|
369
|
+
const {
|
|
370
|
+
fetchApplicationInfo
|
|
371
|
+
} = get();
|
|
346
372
|
try {
|
|
373
|
+
// Buscar application info primeiro (não bloqueia o init)
|
|
374
|
+
fetchApplicationInfo();
|
|
375
|
+
|
|
347
376
|
// Verifica se há um token válido
|
|
348
377
|
if (isAuthenticated()) {
|
|
349
378
|
// Tenta extrair usuário do token (JWT)
|
|
@@ -862,6 +891,13 @@ const useSession = () => useAuthStore(useShallow(s => ({
|
|
|
862
891
|
// Loading States Hook
|
|
863
892
|
const useAuthLoading = () => useAuthStore(s => s.loadingStates);
|
|
864
893
|
|
|
894
|
+
// Application Logo Hook
|
|
895
|
+
const useApplicationLogo = () => {
|
|
896
|
+
const applicationInfo = useAuthStore(s => s.applicationInfo);
|
|
897
|
+
// Retorna o logo da aplicação ou null (componentes usam fallback padrão)
|
|
898
|
+
return applicationInfo?.image || null;
|
|
899
|
+
};
|
|
900
|
+
|
|
865
901
|
function ProtectedRoute({
|
|
866
902
|
fallback = /*#__PURE__*/React.createElement("p", null, "\u231B Carregando..."),
|
|
867
903
|
redirectTo = "/login"
|
|
@@ -897,7 +933,7 @@ function AuthCard({
|
|
|
897
933
|
title,
|
|
898
934
|
subtitle,
|
|
899
935
|
logo,
|
|
900
|
-
logoHeight =
|
|
936
|
+
logoHeight = 28,
|
|
901
937
|
width = 350,
|
|
902
938
|
...props
|
|
903
939
|
}) {
|
|
@@ -932,7 +968,8 @@ var img = "data:image/webp;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAADICAYAAADskzu8AA
|
|
|
932
968
|
*/
|
|
933
969
|
function SignInForm({
|
|
934
970
|
// Configuração
|
|
935
|
-
logo
|
|
971
|
+
logo,
|
|
972
|
+
// Removido default, será calculado abaixo
|
|
936
973
|
title = 'Entrar',
|
|
937
974
|
subtitle = 'Acesse sua conta para continuar',
|
|
938
975
|
// Features
|
|
@@ -958,6 +995,10 @@ function SignInForm({
|
|
|
958
995
|
const loadingSignIn = useAuthStore(s => s.loadingStates.signIn);
|
|
959
996
|
const loadingMagicLink = useAuthStore(s => s.loadingStates.magicLink);
|
|
960
997
|
const loadingResetPassword = useAuthStore(s => s.loadingStates.resetPassword);
|
|
998
|
+
|
|
999
|
+
// Hook para buscar logo da aplicação
|
|
1000
|
+
const applicationLogo = useApplicationLogo();
|
|
1001
|
+
const finalLogo = logo || applicationLogo || img;
|
|
961
1002
|
const form = useForm({
|
|
962
1003
|
initialValues: {
|
|
963
1004
|
email: '',
|
|
@@ -1002,7 +1043,7 @@ function SignInForm({
|
|
|
1002
1043
|
};
|
|
1003
1044
|
const isLoading = loadingSignIn || loadingMagicLink || loadingResetPassword;
|
|
1004
1045
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1005
|
-
logo:
|
|
1046
|
+
logo: finalLogo,
|
|
1006
1047
|
title: title,
|
|
1007
1048
|
subtitle: subtitle
|
|
1008
1049
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1080,7 +1121,7 @@ function SignInForm({
|
|
|
1080
1121
|
*/
|
|
1081
1122
|
function SignUpForm({
|
|
1082
1123
|
// Configuração
|
|
1083
|
-
logo
|
|
1124
|
+
logo,
|
|
1084
1125
|
title = 'Criar Conta',
|
|
1085
1126
|
subtitle = 'Preencha os dados para se cadastrar',
|
|
1086
1127
|
// Features
|
|
@@ -1099,6 +1140,10 @@ function SignUpForm({
|
|
|
1099
1140
|
}) {
|
|
1100
1141
|
const signUp = useAuthStore(s => s.signUp);
|
|
1101
1142
|
const loading = useAuthStore(s => s.loadingStates.signUp);
|
|
1143
|
+
|
|
1144
|
+
// Hook para buscar logo da aplicação
|
|
1145
|
+
const applicationLogo = useApplicationLogo();
|
|
1146
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1102
1147
|
const form = useForm({
|
|
1103
1148
|
initialValues: {
|
|
1104
1149
|
name: '',
|
|
@@ -1122,7 +1167,7 @@ function SignUpForm({
|
|
|
1122
1167
|
}
|
|
1123
1168
|
};
|
|
1124
1169
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1125
|
-
logo:
|
|
1170
|
+
logo: finalLogo,
|
|
1126
1171
|
title: title,
|
|
1127
1172
|
subtitle: subtitle
|
|
1128
1173
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1199,7 +1244,7 @@ function SignUpForm({
|
|
|
1199
1244
|
*/
|
|
1200
1245
|
function MagicLinkForm({
|
|
1201
1246
|
// Configuração
|
|
1202
|
-
logo
|
|
1247
|
+
logo,
|
|
1203
1248
|
title = 'Login sem Senha',
|
|
1204
1249
|
subtitle = 'Receba um link de acesso no seu email',
|
|
1205
1250
|
// Features
|
|
@@ -1215,6 +1260,10 @@ function MagicLinkForm({
|
|
|
1215
1260
|
}) {
|
|
1216
1261
|
const sendMagicLink = useAuthStore(s => s.sendMagicLink);
|
|
1217
1262
|
const loading = useAuthStore(s => s.loadingStates.magicLink);
|
|
1263
|
+
|
|
1264
|
+
// Hook para buscar logo da aplicação
|
|
1265
|
+
const applicationLogo = useApplicationLogo();
|
|
1266
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1218
1267
|
const form = useForm({
|
|
1219
1268
|
initialValues: {
|
|
1220
1269
|
email: ''
|
|
@@ -1232,7 +1281,7 @@ function MagicLinkForm({
|
|
|
1232
1281
|
}
|
|
1233
1282
|
};
|
|
1234
1283
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1235
|
-
logo:
|
|
1284
|
+
logo: finalLogo,
|
|
1236
1285
|
title: title,
|
|
1237
1286
|
subtitle: subtitle
|
|
1238
1287
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1268,7 +1317,7 @@ function MagicLinkForm({
|
|
|
1268
1317
|
*/
|
|
1269
1318
|
function MagicLinkVerify({
|
|
1270
1319
|
// Configuração
|
|
1271
|
-
logo
|
|
1320
|
+
logo,
|
|
1272
1321
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1273
1322
|
token: propToken,
|
|
1274
1323
|
// Callbacks
|
|
@@ -1284,6 +1333,10 @@ function MagicLinkVerify({
|
|
|
1284
1333
|
const [status, setStatus] = useState('verifying'); // verifying, success, error
|
|
1285
1334
|
const [errorMessage, setErrorMessage] = useState('');
|
|
1286
1335
|
const verifyMagicLink = useAuthStore(s => s.verifyMagicLink);
|
|
1336
|
+
|
|
1337
|
+
// Hook para buscar logo da aplicação
|
|
1338
|
+
const applicationLogo = useApplicationLogo();
|
|
1339
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1287
1340
|
const verifyingTokenRef = useRef(null);
|
|
1288
1341
|
useEffect(() => {
|
|
1289
1342
|
const verify = async () => {
|
|
@@ -1322,7 +1375,7 @@ function MagicLinkVerify({
|
|
|
1322
1375
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1323
1376
|
}, [propToken, redirectTo, redirectDelay]);
|
|
1324
1377
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1325
|
-
logo:
|
|
1378
|
+
logo: finalLogo
|
|
1326
1379
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(Stack, {
|
|
1327
1380
|
align: "center",
|
|
1328
1381
|
gap: "sm"
|
|
@@ -1366,7 +1419,7 @@ function MagicLinkVerify({
|
|
|
1366
1419
|
*/
|
|
1367
1420
|
function ForgotPasswordForm({
|
|
1368
1421
|
// Configuração
|
|
1369
|
-
logo
|
|
1422
|
+
logo,
|
|
1370
1423
|
title = 'Recuperar Senha',
|
|
1371
1424
|
subtitle = 'Enviaremos um link para redefinir sua senha',
|
|
1372
1425
|
// Features
|
|
@@ -1382,6 +1435,10 @@ function ForgotPasswordForm({
|
|
|
1382
1435
|
}) {
|
|
1383
1436
|
const forgotPassword = useAuthStore(s => s.forgotPassword);
|
|
1384
1437
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1438
|
+
|
|
1439
|
+
// Hook para buscar logo da aplicação
|
|
1440
|
+
const applicationLogo = useApplicationLogo();
|
|
1441
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1385
1442
|
const form = useForm({
|
|
1386
1443
|
initialValues: {
|
|
1387
1444
|
email: ''
|
|
@@ -1399,7 +1456,7 @@ function ForgotPasswordForm({
|
|
|
1399
1456
|
}
|
|
1400
1457
|
};
|
|
1401
1458
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1402
|
-
logo:
|
|
1459
|
+
logo: finalLogo,
|
|
1403
1460
|
title: title,
|
|
1404
1461
|
subtitle: subtitle
|
|
1405
1462
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1434,7 +1491,7 @@ function ForgotPasswordForm({
|
|
|
1434
1491
|
*/
|
|
1435
1492
|
function ResetPasswordForm({
|
|
1436
1493
|
// Configuração
|
|
1437
|
-
logo
|
|
1494
|
+
logo,
|
|
1438
1495
|
title = 'Nova Senha',
|
|
1439
1496
|
subtitle = 'Crie uma nova senha para sua conta',
|
|
1440
1497
|
// Token pode ser passado diretamente ou extraído da URL
|
|
@@ -1453,6 +1510,10 @@ function ResetPasswordForm({
|
|
|
1453
1510
|
const resetPassword = useAuthStore(s => s.resetPassword);
|
|
1454
1511
|
const loading = useAuthStore(s => s.loadingStates.resetPassword);
|
|
1455
1512
|
|
|
1513
|
+
// Hook para buscar logo da aplicação
|
|
1514
|
+
const applicationLogo = useApplicationLogo();
|
|
1515
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1516
|
+
|
|
1456
1517
|
// Extrai token da URL se não foi passado como prop
|
|
1457
1518
|
useEffect(() => {
|
|
1458
1519
|
if (!propToken && typeof window !== 'undefined') {
|
|
@@ -1486,7 +1547,7 @@ function ResetPasswordForm({
|
|
|
1486
1547
|
};
|
|
1487
1548
|
if (success) {
|
|
1488
1549
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1489
|
-
logo:
|
|
1550
|
+
logo: finalLogo
|
|
1490
1551
|
}, cardProps), /*#__PURE__*/React.createElement(Stack, {
|
|
1491
1552
|
align: "center",
|
|
1492
1553
|
gap: "sm"
|
|
@@ -1507,7 +1568,7 @@ function ResetPasswordForm({
|
|
|
1507
1568
|
}
|
|
1508
1569
|
if (!token) {
|
|
1509
1570
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1510
|
-
logo:
|
|
1571
|
+
logo: finalLogo
|
|
1511
1572
|
}, cardProps), /*#__PURE__*/React.createElement(Stack, {
|
|
1512
1573
|
align: "center",
|
|
1513
1574
|
gap: "sm"
|
|
@@ -1521,7 +1582,7 @@ function ResetPasswordForm({
|
|
|
1521
1582
|
}, labels.goToSignIn || 'Voltar para Login')));
|
|
1522
1583
|
}
|
|
1523
1584
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1524
|
-
logo:
|
|
1585
|
+
logo: finalLogo,
|
|
1525
1586
|
title: title,
|
|
1526
1587
|
subtitle: subtitle
|
|
1527
1588
|
}, cardProps), /*#__PURE__*/React.createElement("form", {
|
|
@@ -1557,7 +1618,7 @@ function ResetPasswordForm({
|
|
|
1557
1618
|
*/
|
|
1558
1619
|
function VerifyEmailCard({
|
|
1559
1620
|
// Configuração
|
|
1560
|
-
logo
|
|
1621
|
+
logo,
|
|
1561
1622
|
// Token pode ser passado diretamente ou extraído da URL
|
|
1562
1623
|
token: propToken,
|
|
1563
1624
|
// Email para reenvio (opcional)
|
|
@@ -1582,6 +1643,10 @@ function VerifyEmailCard({
|
|
|
1582
1643
|
const loadingResend = useAuthStore(s => s.loadingStates.resendVerification);
|
|
1583
1644
|
const user = useAuthStore(s => s.user);
|
|
1584
1645
|
const verifyingTokenRef = useRef(null);
|
|
1646
|
+
|
|
1647
|
+
// Hook para buscar logo da aplicação
|
|
1648
|
+
const applicationLogo = useApplicationLogo();
|
|
1649
|
+
const finalLogo = logo || applicationLogo || img;
|
|
1585
1650
|
useEffect(() => {
|
|
1586
1651
|
const verify = async () => {
|
|
1587
1652
|
// Pega token da prop ou da URL
|
|
@@ -1641,7 +1706,7 @@ function VerifyEmailCard({
|
|
|
1641
1706
|
}
|
|
1642
1707
|
};
|
|
1643
1708
|
return /*#__PURE__*/React.createElement(AuthCard, _extends({
|
|
1644
|
-
logo:
|
|
1709
|
+
logo: finalLogo
|
|
1645
1710
|
}, cardProps), status === 'verifying' && /*#__PURE__*/React.createElement(Stack, {
|
|
1646
1711
|
align: "center",
|
|
1647
1712
|
gap: "sm"
|
|
@@ -1700,5 +1765,5 @@ function VerifyEmailCard({
|
|
|
1700
1765
|
}, labels.resend || 'Solicitar novo link')));
|
|
1701
1766
|
}
|
|
1702
1767
|
|
|
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 };
|
|
1768
|
+
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
1769
|
//# sourceMappingURL=index.esm.js.map
|