autherr 1.0.1 → 1.0.11
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/hooks/useAutherr.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useAutherrContext } from "../provider/AutherrProvider";
|
|
2
2
|
export function useAutherr() {
|
|
3
|
-
const {
|
|
3
|
+
const { accessToken, isAuthenticated, login, signup, logout, getAccessToken, refreshSession, } = useAutherrContext();
|
|
4
4
|
return {
|
|
5
|
-
user,
|
|
6
5
|
accessToken,
|
|
7
6
|
isAuthenticated,
|
|
8
7
|
login,
|
|
@@ -4,7 +4,6 @@ import { fetchSession } from "../api/session";
|
|
|
4
4
|
import { logoutSession } from "../api/logout";
|
|
5
5
|
const AutherrContext = createContext(null);
|
|
6
6
|
export function AutherrProvider({ children, clientId, baseUrl, }) {
|
|
7
|
-
const [user, setUser] = useState(null);
|
|
8
7
|
const [accessToken, setAccessToken] = useState(null);
|
|
9
8
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
10
9
|
const refreshSession = async () => {
|
|
@@ -14,7 +13,6 @@ export function AutherrProvider({ children, clientId, baseUrl, }) {
|
|
|
14
13
|
setIsAuthenticated(true);
|
|
15
14
|
}
|
|
16
15
|
else {
|
|
17
|
-
setUser(null);
|
|
18
16
|
setAccessToken(null);
|
|
19
17
|
setIsAuthenticated(false);
|
|
20
18
|
}
|
|
@@ -43,14 +41,12 @@ export function AutherrProvider({ children, clientId, baseUrl, }) {
|
|
|
43
41
|
await logoutSession(baseUrl, clientId);
|
|
44
42
|
}
|
|
45
43
|
finally {
|
|
46
|
-
setUser(null);
|
|
47
44
|
setAccessToken(null);
|
|
48
45
|
setIsAuthenticated(false);
|
|
49
46
|
window.location.href = window.location.origin;
|
|
50
47
|
}
|
|
51
48
|
};
|
|
52
49
|
const value = useMemo(() => ({
|
|
53
|
-
user,
|
|
54
50
|
accessToken,
|
|
55
51
|
isAuthenticated,
|
|
56
52
|
login,
|
|
@@ -58,7 +54,7 @@ export function AutherrProvider({ children, clientId, baseUrl, }) {
|
|
|
58
54
|
logout,
|
|
59
55
|
refreshSession,
|
|
60
56
|
getAccessToken: () => accessToken,
|
|
61
|
-
}), [
|
|
57
|
+
}), [accessToken, isAuthenticated]);
|
|
62
58
|
return (_jsx(AutherrContext.Provider, { value: value, children: children }));
|
|
63
59
|
}
|
|
64
60
|
export function useAutherrContext() {
|
package/package.json
CHANGED
package/src/hooks/useAutherr.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { useAutherrContext } from "../provider/AutherrProvider";
|
|
|
2
2
|
|
|
3
3
|
export function useAutherr() {
|
|
4
4
|
const {
|
|
5
|
-
user,
|
|
6
5
|
accessToken,
|
|
7
6
|
isAuthenticated,
|
|
8
7
|
login,
|
|
@@ -13,7 +12,6 @@ export function useAutherr() {
|
|
|
13
12
|
} = useAutherrContext();
|
|
14
13
|
|
|
15
14
|
return {
|
|
16
|
-
user,
|
|
17
15
|
accessToken,
|
|
18
16
|
isAuthenticated,
|
|
19
17
|
login,
|