autherr 1.0.0 → 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,
|
|
@@ -10,7 +10,6 @@ import { logoutSession } from "../api/logout";
|
|
|
10
10
|
import { AutherrUser } from "../types/auth";
|
|
11
11
|
|
|
12
12
|
interface AutherrContextValue {
|
|
13
|
-
user: AutherrUser | null;
|
|
14
13
|
accessToken: string | null;
|
|
15
14
|
isAuthenticated: boolean;
|
|
16
15
|
login: () => void;
|
|
@@ -20,6 +19,7 @@ interface AutherrContextValue {
|
|
|
20
19
|
refreshSession: () => Promise<void>;
|
|
21
20
|
}
|
|
22
21
|
|
|
22
|
+
|
|
23
23
|
const AutherrContext = createContext<AutherrContextValue | null>(null);
|
|
24
24
|
|
|
25
25
|
interface AutherrProviderProps {
|
|
@@ -33,7 +33,7 @@ export function AutherrProvider({
|
|
|
33
33
|
clientId,
|
|
34
34
|
baseUrl,
|
|
35
35
|
}: AutherrProviderProps) {
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
const [accessToken, setAccessToken] = useState<string | null>(null);
|
|
38
38
|
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
39
39
|
|
|
@@ -44,7 +44,6 @@ export function AutherrProvider({
|
|
|
44
44
|
setAccessToken(session.accessToken);
|
|
45
45
|
setIsAuthenticated(true);
|
|
46
46
|
} else {
|
|
47
|
-
setUser(null);
|
|
48
47
|
setAccessToken(null);
|
|
49
48
|
setIsAuthenticated(false);
|
|
50
49
|
}
|
|
@@ -77,7 +76,6 @@ export function AutherrProvider({
|
|
|
77
76
|
try {
|
|
78
77
|
await logoutSession(baseUrl, clientId);
|
|
79
78
|
} finally {
|
|
80
|
-
setUser(null);
|
|
81
79
|
setAccessToken(null);
|
|
82
80
|
setIsAuthenticated(false);
|
|
83
81
|
window.location.href = window.location.origin;
|
|
@@ -86,7 +84,6 @@ export function AutherrProvider({
|
|
|
86
84
|
|
|
87
85
|
const value = useMemo(
|
|
88
86
|
() => ({
|
|
89
|
-
user,
|
|
90
87
|
accessToken,
|
|
91
88
|
isAuthenticated,
|
|
92
89
|
login,
|
|
@@ -95,9 +92,10 @@ export function AutherrProvider({
|
|
|
95
92
|
refreshSession,
|
|
96
93
|
getAccessToken: () => accessToken,
|
|
97
94
|
}),
|
|
98
|
-
[
|
|
95
|
+
[accessToken, isAuthenticated]
|
|
99
96
|
);
|
|
100
97
|
|
|
98
|
+
|
|
101
99
|
return (
|
|
102
100
|
<AutherrContext.Provider value={value}>
|
|
103
101
|
{children}
|