@quatrain/auth-supabase 1.2.10 → 1.2.12-beta.0

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.
@@ -14,6 +14,10 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
14
14
  */
15
15
  static factory(config: any): SupabaseAuthAdapter | null;
16
16
  constructor(params?: AuthParameters);
17
+ /**
18
+ * Returns the underlying Supabase Client instance.
19
+ */
20
+ get client(): any;
17
21
  /**
18
22
  * Register new user in authentication
19
23
  * @param user
@@ -25,7 +29,7 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
25
29
  *
26
30
  * @param bearer - Raw JWT string.
27
31
  * @returns The decoded user object.
28
- * @throws {Error} If verification fails.
32
+ * @throws {AuthenticationError} If verification fails.
29
33
  */
30
34
  getAuthToken(bearer: string): Promise<any>;
31
35
  /**
@@ -39,6 +39,12 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
39
39
  });
40
40
  auth_1.Auth.info(`Created Supabase client for ${params.config.supabaseUrl}`);
41
41
  }
42
+ /**
43
+ * Returns the underlying Supabase Client instance.
44
+ */
45
+ get client() {
46
+ return this._client;
47
+ }
42
48
  /**
43
49
  * Register new user in authentication
44
50
  * @param user
@@ -74,15 +80,17 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
74
80
  *
75
81
  * @param bearer - Raw JWT string.
76
82
  * @returns The decoded user object.
77
- * @throws {Error} If verification fails.
83
+ * @throws {AuthenticationError} If verification fails.
78
84
  */
79
85
  getAuthToken(bearer) {
80
86
  return __awaiter(this, void 0, void 0, function* () {
87
+ var _a;
81
88
  const token = yield this._client.auth.getUser(bearer);
82
89
  if (token.data && token.data.user) {
83
90
  return token.data.user;
84
91
  }
85
- throw new Error('Unable to retrieve auth token from Supabase');
92
+ const reason = ((_a = token.error) === null || _a === void 0 ? void 0 : _a.message) ? `: ${token.error.message}` : '';
93
+ throw new auth_1.AuthenticationError(`Unable to retrieve auth token from Supabase${reason}`);
86
94
  });
87
95
  }
88
96
  /**
@@ -164,6 +164,14 @@ describe('SupabaseAuthAdapter', () => {
164
164
  });
165
165
  yield expect(adapter.getAuthToken('invalid-token')).rejects.toThrow('Unable to retrieve auth token from Supabase');
166
166
  }));
167
+ it('should include error message from supabase and throw AuthenticationError when token is invalid or expired', () => __awaiter(void 0, void 0, void 0, function* () {
168
+ mockAuth.getUser.mockResolvedValue({
169
+ data: null,
170
+ error: { message: 'Invalid JWT: token is expired' },
171
+ });
172
+ yield expect(adapter.getAuthToken('expired-token')).rejects.toThrow('Unable to retrieve auth token from Supabase: Invalid JWT: token is expired');
173
+ yield expect(adapter.getAuthToken('expired-token')).rejects.toBeInstanceOf(auth_1.AuthenticationError);
174
+ }));
167
175
  });
168
176
  describe('refreshToken()', () => {
169
177
  it('should successfully refresh token', () => __awaiter(void 0, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-supabase",
3
- "version": "1.2.10",
3
+ "version": "1.2.12-beta.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
21
21
  "dependencies": {
22
- "@quatrain/api": "^1.1.7",
23
- "@quatrain/auth": "^1.2.11",
24
- "@quatrain/backend": "^1.2.17",
22
+ "@quatrain/api": "^1.1.8",
23
+ "@quatrain/auth": "^1.2.13-beta.0",
24
+ "@quatrain/backend": "^1.2.20",
25
25
  "@supabase/supabase-js": "^2.108.2"
26
26
  },
27
27
  "devDependencies": {
@@ -37,6 +37,7 @@
37
37
  "typescript": "^5.2.2"
38
38
  },
39
39
  "scripts": {
40
+ "test": "jest",
40
41
  "test-ci": "jest --runInBand",
41
42
  "build": "tsc",
42
43
  "wbuild": "tsc --watch",
@@ -44,5 +45,6 @@
44
45
  },
45
46
  "typedoc": {
46
47
  "entryPoint": "src/index.ts"
47
- }
48
+ },
49
+ "stableVersion": "1.2.11"
48
50
  }
@@ -211,6 +211,20 @@ describe('SupabaseAuthAdapter', () => {
211
211
  'Unable to retrieve auth token from Supabase'
212
212
  )
213
213
  })
214
+
215
+ it('should include error message from supabase and throw AuthenticationError when token is invalid or expired', async () => {
216
+ mockAuth.getUser.mockResolvedValue({
217
+ data: null,
218
+ error: { message: 'Invalid JWT: token is expired' },
219
+ })
220
+
221
+ await expect(adapter.getAuthToken('expired-token')).rejects.toThrow(
222
+ 'Unable to retrieve auth token from Supabase: Invalid JWT: token is expired'
223
+ )
224
+ await expect(adapter.getAuthToken('expired-token')).rejects.toBeInstanceOf(
225
+ AuthenticationError
226
+ )
227
+ })
214
228
  })
215
229
 
216
230
  describe('refreshToken()', () => {
@@ -44,6 +44,13 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
44
44
  Auth.info(`Created Supabase client for ${params.config.supabaseUrl}`)
45
45
  }
46
46
 
47
+ /**
48
+ * Returns the underlying Supabase Client instance.
49
+ */
50
+ public get client(): any {
51
+ return this._client
52
+ }
53
+
47
54
  /**
48
55
  * Register new user in authentication
49
56
  * @param user
@@ -85,14 +92,15 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
85
92
  *
86
93
  * @param bearer - Raw JWT string.
87
94
  * @returns The decoded user object.
88
- * @throws {Error} If verification fails.
95
+ * @throws {AuthenticationError} If verification fails.
89
96
  */
90
97
  async getAuthToken(bearer: string) {
91
98
  const token = await this._client.auth.getUser(bearer)
92
99
  if (token.data && token.data.user) {
93
100
  return token.data.user
94
101
  }
95
- throw new Error('Unable to retrieve auth token from Supabase')
102
+ const reason = token.error?.message ? `: ${token.error.message}` : ''
103
+ throw new AuthenticationError(`Unable to retrieve auth token from Supabase${reason}`)
96
104
  }
97
105
 
98
106
  /**