@quatrain/auth-supabase 1.2.5 → 1.2.7
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.
|
@@ -79,4 +79,11 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
79
79
|
* @returns Resolved updated user wrapper.
|
|
80
80
|
*/
|
|
81
81
|
setCustomUserClaims(id: string, claims: any): Promise<any>;
|
|
82
|
+
/**
|
|
83
|
+
* Initiates password recovery/reset process for a user.
|
|
84
|
+
*
|
|
85
|
+
* @param email - The user email.
|
|
86
|
+
* @param redirectTo - Optional redirect destination.
|
|
87
|
+
*/
|
|
88
|
+
recoverPassword(email: string, redirectTo?: string): Promise<any>;
|
|
82
89
|
}
|
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -246,5 +254,22 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
246
254
|
}
|
|
247
255
|
});
|
|
248
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Initiates password recovery/reset process for a user.
|
|
259
|
+
*
|
|
260
|
+
* @param email - The user email.
|
|
261
|
+
* @param redirectTo - Optional redirect destination.
|
|
262
|
+
*/
|
|
263
|
+
recoverPassword(email, redirectTo) {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
const { data, error } = yield this._client.auth.resetPasswordForEmail(email, {
|
|
266
|
+
redirectTo,
|
|
267
|
+
});
|
|
268
|
+
if (error) {
|
|
269
|
+
throw new Error(error.message);
|
|
270
|
+
}
|
|
271
|
+
return data;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
249
274
|
}
|
|
250
275
|
exports.SupabaseAuthAdapter = SupabaseAuthAdapter;
|
|
@@ -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
|
|
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
|
-
|
|
347
|
-
|
|
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.
|
|
3
|
+
"version": "1.2.7",
|
|
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.
|
|
23
|
-
"@quatrain/auth": "^1.2.
|
|
24
|
-
"@quatrain/backend": "^1.2.
|
|
22
|
+
"@quatrain/api": "^1.1.6",
|
|
23
|
+
"@quatrain/auth": "^1.2.5",
|
|
24
|
+
"@quatrain/backend": "^1.2.14",
|
|
25
25
|
"@supabase/supabase-js": "^2.87.3",
|
|
26
26
|
"node-fetch-native": "^1.6.4"
|
|
27
27
|
},
|
|
@@ -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
|
|
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
|
-
|
|
419
|
+
await expect(adapter.update(mockUser, updatable)).rejects.toThrow(
|
|
420
|
+
AuthenticationError
|
|
421
|
+
)
|
|
422
|
+
})
|
|
419
423
|
|
|
420
|
-
|
|
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
|
-
|
|
197
|
+
if (e instanceof AuthenticationError) {
|
|
198
|
+
throw e
|
|
199
|
+
}
|
|
200
|
+
throw new AuthenticationError((e as Error).message)
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
203
|
|
|
@@ -222,4 +229,20 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
222
229
|
return data
|
|
223
230
|
}
|
|
224
231
|
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Initiates password recovery/reset process for a user.
|
|
235
|
+
*
|
|
236
|
+
* @param email - The user email.
|
|
237
|
+
* @param redirectTo - Optional redirect destination.
|
|
238
|
+
*/
|
|
239
|
+
async recoverPassword(email: string, redirectTo?: string) {
|
|
240
|
+
const { data, error } = await this._client.auth.resetPasswordForEmail(email, {
|
|
241
|
+
redirectTo,
|
|
242
|
+
})
|
|
243
|
+
if (error) {
|
|
244
|
+
throw new Error(error.message)
|
|
245
|
+
}
|
|
246
|
+
return data
|
|
247
|
+
}
|
|
225
248
|
}
|