@go-avro/avro-js 0.0.2-beta.78 → 0.0.2-beta.79

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.
@@ -261,6 +261,10 @@ export declare class AvroQueryClient {
261
261
  code?: string;
262
262
  cancelToken?: CancelToken;
263
263
  }>>;
264
+ useGoogleLogin(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
265
+ token: string;
266
+ cancelToken?: CancelToken;
267
+ }>>;
264
268
  setTokens(tokens: Tokens): Promise<void>;
265
269
  clearTokens(): Promise<void>;
266
270
  isAuthenticated(): boolean;
@@ -101,6 +101,34 @@ export class AvroQueryClient {
101
101
  }
102
102
  });
103
103
  }
104
+ useGoogleLogin() {
105
+ const queryClient = useQueryClient();
106
+ return useMutation({
107
+ mutationFn: async ({ token, cancelToken }) => {
108
+ const resp = await this._fetch('POST', `/google/authorize?token=${token}`, {}, cancelToken, { 'Content-Type': 'application/json' });
109
+ if (!resp || !('access_token' in resp)) {
110
+ if (resp.msg === "TOTP email sent") {
111
+ return LoginResponse.NEEDS_TOTP;
112
+ }
113
+ throw new StandardError(401, 'Invalid Google login response');
114
+ }
115
+ this.socket.auth = { token: resp.access_token };
116
+ if (!this.socket.connected) {
117
+ this.socket.connect();
118
+ }
119
+ await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
120
+ return LoginResponse.SUCCESS;
121
+ },
122
+ onSettled: () => {
123
+ queryClient.invalidateQueries();
124
+ },
125
+ onError: (err) => {
126
+ this.config.authManager.clearTokens();
127
+ console.error('Google login failed:', err);
128
+ throw new StandardError(401, 'Google login failed');
129
+ }
130
+ });
131
+ }
104
132
  setTokens(tokens) {
105
133
  return this.config.authManager.setTokens(tokens);
106
134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.78",
3
+ "version": "0.0.2-beta.79",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",