@go-avro/avro-js 0.0.2-beta.75 → 0.0.2-beta.77
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.
|
@@ -254,11 +254,12 @@ export declare class AvroQueryClient {
|
|
|
254
254
|
post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
255
255
|
put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
256
256
|
delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
257
|
-
|
|
257
|
+
useLogin(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
|
|
258
258
|
username: string;
|
|
259
259
|
password: string;
|
|
260
260
|
code?: string;
|
|
261
|
-
|
|
261
|
+
cancelToken?: CancelToken;
|
|
262
|
+
}>>;
|
|
262
263
|
setTokens(tokens: Tokens): Promise<void>;
|
|
263
264
|
clearTokens(): Promise<void>;
|
|
264
265
|
useLogout(): ReturnType<typeof useMutation<void, StandardError, CancelToken | undefined>>;
|
|
@@ -61,26 +61,32 @@ export class AvroQueryClient {
|
|
|
61
61
|
delete(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
62
62
|
return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
useLogin() {
|
|
65
|
+
const queryClient = useQueryClient();
|
|
66
|
+
return useMutation({
|
|
67
|
+
mutationFn: async ({ username, password, code, cancelToken }) => {
|
|
68
|
+
const resp = await this._fetch('POST', '/login', { username, password, code }, cancelToken);
|
|
69
|
+
if (!resp || !('access_token' in resp)) {
|
|
70
|
+
if (resp.msg === "TOTP email sent") {
|
|
71
|
+
return LoginResponse.NEEDS_TOTP;
|
|
72
|
+
}
|
|
73
|
+
throw new StandardError(401, 'Invalid login response');
|
|
70
74
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.
|
|
76
|
-
}
|
|
77
|
-
return this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token }).then(() => {
|
|
75
|
+
this.socket.auth = { token: resp.access_token };
|
|
76
|
+
if (!this.socket.connected) {
|
|
77
|
+
this.socket.connect();
|
|
78
|
+
}
|
|
79
|
+
await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
78
80
|
return LoginResponse.SUCCESS;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
},
|
|
82
|
+
onSettled: () => {
|
|
83
|
+
queryClient.invalidateQueries();
|
|
84
|
+
},
|
|
85
|
+
onError: (err) => {
|
|
86
|
+
this.config.authManager.clearTokens();
|
|
87
|
+
console.error('Login failed:', err);
|
|
88
|
+
throw new StandardError(401, 'Login failed');
|
|
89
|
+
}
|
|
84
90
|
});
|
|
85
91
|
}
|
|
86
92
|
setTokens(tokens) {
|
package/dist/types/api.d.ts
CHANGED