@addev-be/ui 0.7.4 → 0.7.5
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/package.json
CHANGED
|
@@ -32,6 +32,7 @@ export type AuthenticationContextProps = {
|
|
|
32
32
|
resetPassword: (key: string, password: string) => Promise<number>;
|
|
33
33
|
permissions: Record<string, string>;
|
|
34
34
|
hasPermission: (permission: string) => boolean;
|
|
35
|
+
setToken: (token?: string) => void;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
export const AuthenticationContext = createContext<AuthenticationContextProps>({
|
|
@@ -44,6 +45,7 @@ export const AuthenticationContext = createContext<AuthenticationContextProps>({
|
|
|
44
45
|
resetPassword: async () => -1,
|
|
45
46
|
permissions: {},
|
|
46
47
|
hasPermission: () => false,
|
|
48
|
+
setToken: () => {},
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
export type AuthenticationProviderProps = PropsWithChildren<{
|
|
@@ -77,14 +79,6 @@ export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
|
77
79
|
const sendCheckRecoveryKeyRequest = useCheckRecoveryKeyRequestHandler();
|
|
78
80
|
const sendResetPasswordRequest = useResetPasswordRequestHandler();
|
|
79
81
|
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (token) {
|
|
82
|
-
sessionStorage.setItem('authToken', token);
|
|
83
|
-
} else {
|
|
84
|
-
sessionStorage.removeItem('authToken');
|
|
85
|
-
}
|
|
86
|
-
}, [token]);
|
|
87
|
-
|
|
88
82
|
const authenticate = useCallback(() => {
|
|
89
83
|
if (token && !user) {
|
|
90
84
|
sendAuthenticateRequest({ token }).then(
|
|
@@ -104,6 +98,15 @@ export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
|
104
98
|
}
|
|
105
99
|
}, [sendAuthenticateRequest, token, user]);
|
|
106
100
|
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (token) {
|
|
103
|
+
sessionStorage.setItem('authToken', token);
|
|
104
|
+
authenticate();
|
|
105
|
+
} else {
|
|
106
|
+
sessionStorage.removeItem('authToken');
|
|
107
|
+
}
|
|
108
|
+
}, [authenticate, token]);
|
|
109
|
+
|
|
107
110
|
const login = useCallback(
|
|
108
111
|
async (username: string, password: string) =>
|
|
109
112
|
sendLoginRequest({ username, password })
|
|
@@ -190,6 +193,7 @@ export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
|
190
193
|
resetPassword,
|
|
191
194
|
permissions: allPermissions,
|
|
192
195
|
hasPermission,
|
|
196
|
+
setToken,
|
|
193
197
|
}),
|
|
194
198
|
[
|
|
195
199
|
allPermissions,
|
|
@@ -202,6 +206,7 @@ export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
|
202
206
|
sendRecoveryKey,
|
|
203
207
|
token,
|
|
204
208
|
user,
|
|
209
|
+
setToken,
|
|
205
210
|
]
|
|
206
211
|
);
|
|
207
212
|
|