@redzone/taunt-logins-ui-react 0.0.25 → 0.0.26
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/cjs/index.cjs +29 -7
- package/dist/es/index.js +29 -7
- package/package.json +2 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -560,6 +560,13 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
560
560
|
]);
|
|
561
561
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
562
562
|
const loggedIn = !!tauntUser;
|
|
563
|
+
react.useEffect(()=>{
|
|
564
|
+
if (!tauntUser) {
|
|
565
|
+
setLoginDetails(undefined);
|
|
566
|
+
}
|
|
567
|
+
}, [
|
|
568
|
+
tauntUser
|
|
569
|
+
]);
|
|
563
570
|
const getMe = react.useCallback(async (force = false)=>{
|
|
564
571
|
if (!force && !loggedIn) return undefined;
|
|
565
572
|
return taunt.getLoggedInUser();
|
|
@@ -634,26 +641,35 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
634
641
|
return Promise.resolve(undefined);
|
|
635
642
|
}, []);
|
|
636
643
|
const logout = react.useCallback(()=>{
|
|
637
|
-
void taunt.logout().
|
|
644
|
+
void taunt.logout().finally(()=>{
|
|
638
645
|
setTauntUser(undefined);
|
|
639
646
|
});
|
|
640
647
|
}, [
|
|
641
648
|
taunt
|
|
642
649
|
]);
|
|
643
|
-
const refreshToken = react.useCallback(async (token)=>{
|
|
644
|
-
if (!token)
|
|
650
|
+
const refreshToken = react.useCallback(async (token, autoLogoutOnError = true)=>{
|
|
651
|
+
if (!token) {
|
|
652
|
+
if (autoLogoutOnError) {
|
|
653
|
+
logout();
|
|
654
|
+
}
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
645
657
|
setIsLoading(true);
|
|
646
658
|
try {
|
|
647
659
|
await taunt.refresh(token);
|
|
648
660
|
return await refreshUser();
|
|
649
661
|
} catch (error) {
|
|
650
662
|
console.error("Failed to refresh token:", error);
|
|
663
|
+
if (autoLogoutOnError) {
|
|
664
|
+
logout();
|
|
665
|
+
}
|
|
651
666
|
} finally{
|
|
652
667
|
setIsLoading(false);
|
|
653
668
|
}
|
|
654
669
|
}, [
|
|
670
|
+
taunt,
|
|
655
671
|
refreshUser,
|
|
656
|
-
|
|
672
|
+
logout
|
|
657
673
|
]);
|
|
658
674
|
const withTaunt = react.useCallback(async (fn)=>{
|
|
659
675
|
if (loggedIn) {
|
|
@@ -677,13 +693,19 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
677
693
|
return loginDetails;
|
|
678
694
|
}
|
|
679
695
|
if (loggedIn) {
|
|
680
|
-
|
|
681
|
-
|
|
696
|
+
if (taunt.refreshToken) {
|
|
697
|
+
setLoginDetails(await refreshToken(taunt.refreshToken));
|
|
698
|
+
return loginDetails;
|
|
699
|
+
} else {
|
|
700
|
+
logout();
|
|
701
|
+
}
|
|
682
702
|
}
|
|
683
703
|
}, [
|
|
684
704
|
loggedIn,
|
|
685
705
|
loginDetails,
|
|
686
|
-
taunt
|
|
706
|
+
taunt.refreshToken,
|
|
707
|
+
refreshToken,
|
|
708
|
+
logout
|
|
687
709
|
]);
|
|
688
710
|
const safeSetLoginDetails = react.useCallback((props)=>loginWith(async ({ taunt })=>{
|
|
689
711
|
await taunt.setLoginDetails(props);
|
package/dist/es/index.js
CHANGED
|
@@ -560,6 +560,13 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
560
560
|
]);
|
|
561
561
|
const [isLoading, setIsLoading] = useState(false);
|
|
562
562
|
const loggedIn = !!tauntUser;
|
|
563
|
+
useEffect(()=>{
|
|
564
|
+
if (!tauntUser) {
|
|
565
|
+
setLoginDetails(undefined);
|
|
566
|
+
}
|
|
567
|
+
}, [
|
|
568
|
+
tauntUser
|
|
569
|
+
]);
|
|
563
570
|
const getMe = useCallback(async (force = false)=>{
|
|
564
571
|
if (!force && !loggedIn) return undefined;
|
|
565
572
|
return taunt.getLoggedInUser();
|
|
@@ -634,26 +641,35 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
634
641
|
return Promise.resolve(undefined);
|
|
635
642
|
}, []);
|
|
636
643
|
const logout = useCallback(()=>{
|
|
637
|
-
void taunt.logout().
|
|
644
|
+
void taunt.logout().finally(()=>{
|
|
638
645
|
setTauntUser(undefined);
|
|
639
646
|
});
|
|
640
647
|
}, [
|
|
641
648
|
taunt
|
|
642
649
|
]);
|
|
643
|
-
const refreshToken = useCallback(async (token)=>{
|
|
644
|
-
if (!token)
|
|
650
|
+
const refreshToken = useCallback(async (token, autoLogoutOnError = true)=>{
|
|
651
|
+
if (!token) {
|
|
652
|
+
if (autoLogoutOnError) {
|
|
653
|
+
logout();
|
|
654
|
+
}
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
645
657
|
setIsLoading(true);
|
|
646
658
|
try {
|
|
647
659
|
await taunt.refresh(token);
|
|
648
660
|
return await refreshUser();
|
|
649
661
|
} catch (error) {
|
|
650
662
|
console.error("Failed to refresh token:", error);
|
|
663
|
+
if (autoLogoutOnError) {
|
|
664
|
+
logout();
|
|
665
|
+
}
|
|
651
666
|
} finally{
|
|
652
667
|
setIsLoading(false);
|
|
653
668
|
}
|
|
654
669
|
}, [
|
|
670
|
+
taunt,
|
|
655
671
|
refreshUser,
|
|
656
|
-
|
|
672
|
+
logout
|
|
657
673
|
]);
|
|
658
674
|
const withTaunt = useCallback(async (fn)=>{
|
|
659
675
|
if (loggedIn) {
|
|
@@ -677,13 +693,19 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
677
693
|
return loginDetails;
|
|
678
694
|
}
|
|
679
695
|
if (loggedIn) {
|
|
680
|
-
|
|
681
|
-
|
|
696
|
+
if (taunt.refreshToken) {
|
|
697
|
+
setLoginDetails(await refreshToken(taunt.refreshToken));
|
|
698
|
+
return loginDetails;
|
|
699
|
+
} else {
|
|
700
|
+
logout();
|
|
701
|
+
}
|
|
682
702
|
}
|
|
683
703
|
}, [
|
|
684
704
|
loggedIn,
|
|
685
705
|
loginDetails,
|
|
686
|
-
taunt
|
|
706
|
+
taunt.refreshToken,
|
|
707
|
+
refreshToken,
|
|
708
|
+
logout
|
|
687
709
|
]);
|
|
688
710
|
const safeSetLoginDetails = useCallback((props)=>loginWith(async ({ taunt })=>{
|
|
689
711
|
await taunt.setLoginDetails(props);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redzone/taunt-logins-ui-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/es/index.js",
|
|
6
6
|
"module": "./dist/es/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"postbuild": "npm run copy:styles",
|
|
31
31
|
"clean": "rm -rf dist",
|
|
32
32
|
"lint": "eslint .",
|
|
33
|
+
"npm:login": "npm login",
|
|
33
34
|
"prenpm:publish": "npm run build",
|
|
34
35
|
"npm:publish": "npm publish --access public",
|
|
35
36
|
"fb:login": "firebase login --reauth",
|