@quatrain/auth-supabase 1.2.6 → 1.2.9

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.
@@ -199,19 +199,27 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
199
199
  */
200
200
  update(user, updatable) {
201
201
  return __awaiter(this, void 0, void 0, function* () {
202
+ var _a;
202
203
  auth_1.Auth.debug('auth data to update', JSON.stringify(updatable));
203
204
  try {
204
205
  if (Object.keys(updatable).length > 0) {
205
206
  auth_1.Auth.info(`Updating ${updatable.displayName} Auth record`);
206
207
  const { error } = yield this._client.auth.admin.updateUserById(user.uid, updatable);
207
208
  if (error !== null) {
208
- auth_1.Auth.error(error);
209
+ auth_1.Auth.error(error.message);
210
+ if (error.code === 'weak_password' || ((_a = error.message) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('password'))) {
211
+ throw new auth_1.AuthenticationError(auth_1.Auth.ERROR_WEAK_PASSWORD);
212
+ }
213
+ throw new auth_1.AuthenticationError(error.message);
209
214
  }
210
215
  }
211
216
  }
212
217
  catch (e) {
213
218
  auth_1.Auth.error(e);
214
- return false;
219
+ if (e instanceof auth_1.AuthenticationError) {
220
+ throw e;
221
+ }
222
+ throw new auth_1.AuthenticationError(e.message);
215
223
  }
216
224
  });
217
225
  }
@@ -336,15 +336,21 @@ describe('SupabaseAuthAdapter', () => {
336
336
  data: null,
337
337
  error: { message: 'Update failed' },
338
338
  });
339
- yield adapter.update(mockUser, updatable);
340
- // The method doesn't throw, just logs the error
339
+ yield expect(adapter.update(mockUser, updatable)).rejects.toThrow(auth_1.AuthenticationError);
341
340
  expect(mockAuthAdmin.updateUserById).toHaveBeenCalledWith('user-123', updatable);
342
341
  }));
343
- it('should return false on exception', () => __awaiter(void 0, void 0, void 0, function* () {
342
+ it('should throw AuthenticationError on exception', () => __awaiter(void 0, void 0, void 0, function* () {
344
343
  const updatable = { displayName: 'New Name' };
345
344
  mockAuthAdmin.updateUserById.mockRejectedValue(new Error('Network error'));
346
- const result = yield adapter.update(mockUser, updatable);
347
- expect(result).toBe(false);
345
+ yield expect(adapter.update(mockUser, updatable)).rejects.toThrow(auth_1.AuthenticationError);
346
+ }));
347
+ it('should throw Auth.ERROR_WEAK_PASSWORD on weak password error', () => __awaiter(void 0, void 0, void 0, function* () {
348
+ const updatable = { password: '123' };
349
+ mockAuthAdmin.updateUserById.mockResolvedValue({
350
+ data: null,
351
+ error: { code: 'weak_password', message: 'Password should be stronger' },
352
+ });
353
+ yield expect(adapter.update(mockUser, updatable)).rejects.toThrow('weak_password');
348
354
  }));
349
355
  });
350
356
  describe('delete()', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-supabase",
3
- "version": "1.2.6",
3
+ "version": "1.2.9",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
21
21
  "dependencies": {
22
22
  "@quatrain/api": "^1.1.6",
23
- "@quatrain/auth": "^1.2.4",
24
- "@quatrain/backend": "^1.2.13",
25
- "@supabase/supabase-js": "^2.87.3",
23
+ "@quatrain/auth": "^1.2.7",
24
+ "@quatrain/backend": "^1.2.17",
25
+ "@supabase/supabase-js": "^2.108.2",
26
26
  "node-fetch-native": "^1.6.4"
27
27
  },
28
28
  "devDependencies": {
@@ -399,25 +399,39 @@ describe('SupabaseAuthAdapter', () => {
399
399
  error: { message: 'Update failed' },
400
400
  })
401
401
 
402
- await adapter.update(mockUser, updatable)
402
+ await expect(adapter.update(mockUser, updatable)).rejects.toThrow(
403
+ AuthenticationError
404
+ )
403
405
 
404
- // The method doesn't throw, just logs the error
405
406
  expect(mockAuthAdmin.updateUserById).toHaveBeenCalledWith(
406
407
  'user-123',
407
408
  updatable
408
409
  )
409
410
  })
410
411
 
411
- it('should return false on exception', async () => {
412
+ it('should throw AuthenticationError on exception', async () => {
412
413
  const updatable = { displayName: 'New Name' }
413
414
 
414
415
  mockAuthAdmin.updateUserById.mockRejectedValue(
415
416
  new Error('Network error')
416
417
  )
417
418
 
418
- const result = await adapter.update(mockUser, updatable)
419
+ await expect(adapter.update(mockUser, updatable)).rejects.toThrow(
420
+ AuthenticationError
421
+ )
422
+ })
419
423
 
420
- expect(result).toBe(false)
424
+ it('should throw Auth.ERROR_WEAK_PASSWORD on weak password error', async () => {
425
+ const updatable = { password: '123' }
426
+
427
+ mockAuthAdmin.updateUserById.mockResolvedValue({
428
+ data: null,
429
+ error: { code: 'weak_password', message: 'Password should be stronger' },
430
+ })
431
+
432
+ await expect(adapter.update(mockUser, updatable)).rejects.toThrow(
433
+ 'weak_password'
434
+ )
421
435
  })
422
436
  })
423
437
 
@@ -185,12 +185,19 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
185
185
  updatable
186
186
  )
187
187
  if (error !== null) {
188
- Auth.error(error)
188
+ Auth.error(error.message)
189
+ if (error.code === 'weak_password' || error.message?.toLowerCase().includes('password')) {
190
+ throw new AuthenticationError(Auth.ERROR_WEAK_PASSWORD)
191
+ }
192
+ throw new AuthenticationError(error.message)
189
193
  }
190
194
  }
191
195
  } catch (e) {
192
196
  Auth.error(e)
193
- return false
197
+ if (e instanceof AuthenticationError) {
198
+ throw e
199
+ }
200
+ throw new AuthenticationError((e as Error).message)
194
201
  }
195
202
  }
196
203