@go-avro/avro-js 0.0.2-beta.4 → 0.0.2-beta.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.
@@ -6,7 +6,7 @@ export declare class AuthManager {
6
6
  baseUrl: string;
7
7
  storage: TokenStorage | TokenStorage[];
8
8
  });
9
- hasTokens(): Promise<boolean>;
9
+ isAuthenticated(): Promise<boolean>;
10
10
  fetchNewTokens(): Promise<Tokens>;
11
11
  accessToken(): Promise<string | undefined>;
12
12
  refreshTokens(): Promise<Tokens | null>;
@@ -11,11 +11,26 @@ export class AuthManager {
11
11
  });
12
12
  this.baseUrl = baseUrl;
13
13
  }
14
- async hasTokens() {
14
+ async isAuthenticated() {
15
+ if (!this.storages.length) {
16
+ throw new Error('No token storages initialized');
17
+ }
15
18
  for (const storage of this.storages) {
16
19
  const tokens = await storage.get();
17
20
  if (tokens && tokens.access_token) {
18
- return true;
21
+ try {
22
+ const response = await fetch(`${this.baseUrl}/validate`, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ 'Authorization': `Bearer ${tokens.access_token}`,
27
+ },
28
+ });
29
+ return response.ok;
30
+ }
31
+ catch (error) {
32
+ console.error('Error validating access token:', error);
33
+ }
19
34
  }
20
35
  }
21
36
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.4",
3
+ "version": "0.0.2-beta.5",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",