@redzone/taunt-logins-ui-react 0.0.25 → 0.0.27
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 +32 -9
- package/dist/es/index.js +32 -9
- 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,36 @@ 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
|
-
await taunt.refresh(token);
|
|
648
|
-
|
|
659
|
+
const details = await taunt.refresh(token);
|
|
660
|
+
await refreshUser();
|
|
661
|
+
return details;
|
|
649
662
|
} catch (error) {
|
|
650
663
|
console.error("Failed to refresh token:", error);
|
|
664
|
+
if (autoLogoutOnError) {
|
|
665
|
+
logout();
|
|
666
|
+
}
|
|
651
667
|
} finally{
|
|
652
668
|
setIsLoading(false);
|
|
653
669
|
}
|
|
654
670
|
}, [
|
|
671
|
+
taunt,
|
|
655
672
|
refreshUser,
|
|
656
|
-
|
|
673
|
+
logout
|
|
657
674
|
]);
|
|
658
675
|
const withTaunt = react.useCallback(async (fn)=>{
|
|
659
676
|
if (loggedIn) {
|
|
@@ -677,13 +694,19 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
677
694
|
return loginDetails;
|
|
678
695
|
}
|
|
679
696
|
if (loggedIn) {
|
|
680
|
-
|
|
681
|
-
|
|
697
|
+
if (taunt.refreshToken) {
|
|
698
|
+
setLoginDetails(await refreshToken(taunt.refreshToken));
|
|
699
|
+
return loginDetails;
|
|
700
|
+
} else {
|
|
701
|
+
logout();
|
|
702
|
+
}
|
|
682
703
|
}
|
|
683
704
|
}, [
|
|
684
705
|
loggedIn,
|
|
685
706
|
loginDetails,
|
|
686
|
-
taunt
|
|
707
|
+
taunt.refreshToken,
|
|
708
|
+
refreshToken,
|
|
709
|
+
logout
|
|
687
710
|
]);
|
|
688
711
|
const safeSetLoginDetails = react.useCallback((props)=>loginWith(async ({ taunt })=>{
|
|
689
712
|
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,36 @@ 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
|
-
await taunt.refresh(token);
|
|
648
|
-
|
|
659
|
+
const details = await taunt.refresh(token);
|
|
660
|
+
await refreshUser();
|
|
661
|
+
return details;
|
|
649
662
|
} catch (error) {
|
|
650
663
|
console.error("Failed to refresh token:", error);
|
|
664
|
+
if (autoLogoutOnError) {
|
|
665
|
+
logout();
|
|
666
|
+
}
|
|
651
667
|
} finally{
|
|
652
668
|
setIsLoading(false);
|
|
653
669
|
}
|
|
654
670
|
}, [
|
|
671
|
+
taunt,
|
|
655
672
|
refreshUser,
|
|
656
|
-
|
|
673
|
+
logout
|
|
657
674
|
]);
|
|
658
675
|
const withTaunt = useCallback(async (fn)=>{
|
|
659
676
|
if (loggedIn) {
|
|
@@ -677,13 +694,19 @@ const TauntProvider = ({ children, tauntServiceEndpoint, magicKey })=>{
|
|
|
677
694
|
return loginDetails;
|
|
678
695
|
}
|
|
679
696
|
if (loggedIn) {
|
|
680
|
-
|
|
681
|
-
|
|
697
|
+
if (taunt.refreshToken) {
|
|
698
|
+
setLoginDetails(await refreshToken(taunt.refreshToken));
|
|
699
|
+
return loginDetails;
|
|
700
|
+
} else {
|
|
701
|
+
logout();
|
|
702
|
+
}
|
|
682
703
|
}
|
|
683
704
|
}, [
|
|
684
705
|
loggedIn,
|
|
685
706
|
loginDetails,
|
|
686
|
-
taunt
|
|
707
|
+
taunt.refreshToken,
|
|
708
|
+
refreshToken,
|
|
709
|
+
logout
|
|
687
710
|
]);
|
|
688
711
|
const safeSetLoginDetails = useCallback((props)=>loginWith(async ({ taunt })=>{
|
|
689
712
|
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.27",
|
|
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",
|