@quatrain/auth-supabase 1.2.4 → 1.2.6

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.
@@ -1,6 +1,5 @@
1
1
  import { User } from '@quatrain/backend';
2
2
  import { AbstractAuthAdapter, AuthParameters } from '@quatrain/auth';
3
- import { ApiMiddleware } from '@quatrain/api';
4
3
  /**
5
4
  * Authentication adapter implementing the Supabase SDK ecosystem.
6
5
  * Acts as a centralized bridge handling signup, tokens, and middleware enforcement.
@@ -14,12 +13,6 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
14
13
  * @returns A constructed SupabaseAuthAdapter or null on invalid params.
15
14
  */
16
15
  static factory(config: any): SupabaseAuthAdapter | null;
17
- /**
18
- * Express middleware capturing Bearer JWT tokens to execute auth verification.
19
- *
20
- * @returns The middleware function.
21
- */
22
- middleware(): ApiMiddleware;
23
16
  constructor(params?: AuthParameters);
24
17
  /**
25
18
  * Register new user in authentication
@@ -86,4 +79,11 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
86
79
  * @returns Resolved updated user wrapper.
87
80
  */
88
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>;
89
89
  }
@@ -63,31 +63,6 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
63
63
  return null;
64
64
  return new SupabaseAuthAdapter({ config });
65
65
  }
66
- /**
67
- * Express middleware capturing Bearer JWT tokens to execute auth verification.
68
- *
69
- * @returns The middleware function.
70
- */
71
- middleware() {
72
- return (req, res) => __awaiter(this, void 0, void 0, function* () {
73
- var _a;
74
- const bearer = (((_a = req.headers) === null || _a === void 0 ? void 0 : _a.authorization) || '').split(' ')[1] || '';
75
- if (bearer) {
76
- try {
77
- const user = yield this.getAuthToken(bearer);
78
- if (user) {
79
- return true; // Authorized
80
- }
81
- }
82
- catch (e) {
83
- auth_1.Auth.error(`[SupabaseAuthAdapter] Middleware token verification failed: ${e.message}`);
84
- }
85
- }
86
- res.setHeader('WWW-Authenticate', 'Bearer realm="Core API"');
87
- res.status(401).send('Authentication required.');
88
- return false;
89
- });
90
- }
91
66
  constructor(params = {}) {
92
67
  super(params);
93
68
  this._client = (0, supabase_js_1.createClient)(params.config.supabaseUrl, params.config.supabaseKey, {
@@ -271,5 +246,22 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
271
246
  }
272
247
  });
273
248
  }
249
+ /**
250
+ * Initiates password recovery/reset process for a user.
251
+ *
252
+ * @param email - The user email.
253
+ * @param redirectTo - Optional redirect destination.
254
+ */
255
+ recoverPassword(email, redirectTo) {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ const { data, error } = yield this._client.auth.resetPasswordForEmail(email, {
258
+ redirectTo,
259
+ });
260
+ if (error) {
261
+ throw new Error(error.message);
262
+ }
263
+ return data;
264
+ });
265
+ }
274
266
  }
275
267
  exports.SupabaseAuthAdapter = SupabaseAuthAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-supabase",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
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.5",
23
- "@quatrain/auth": "^1.2.2",
24
- "@quatrain/backend": "^1.2.6",
22
+ "@quatrain/api": "^1.1.6",
23
+ "@quatrain/auth": "^1.2.4",
24
+ "@quatrain/backend": "^1.2.13",
25
25
  "@supabase/supabase-js": "^2.87.3",
26
26
  "node-fetch-native": "^1.6.4"
27
27
  },
@@ -5,7 +5,7 @@ import {
5
5
  AuthenticationError,
6
6
  AuthParameters,
7
7
  } from '@quatrain/auth'
8
- import { ApiMiddleware, ApiRequest, ApiResponse } from '@quatrain/api'
8
+
9
9
  import { createClient } from '@supabase/supabase-js'
10
10
  import * as nativeFetch from 'node-fetch-native'
11
11
 
@@ -28,31 +28,7 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
28
28
  return new SupabaseAuthAdapter({ config })
29
29
  }
30
30
 
31
- /**
32
- * Express middleware capturing Bearer JWT tokens to execute auth verification.
33
- *
34
- * @returns The middleware function.
35
- */
36
- public middleware(): ApiMiddleware {
37
- return async (req: ApiRequest, res: ApiResponse): Promise<boolean> => {
38
- const bearer = ((req.headers?.authorization as string) || '').split(' ')[1] || ''
39
-
40
- if (bearer) {
41
- try {
42
- const user = await this.getAuthToken(bearer)
43
- if (user) {
44
- return true // Authorized
45
- }
46
- } catch(e) {
47
- Auth.error(`[SupabaseAuthAdapter] Middleware token verification failed: ${(e as Error).message}`)
48
- }
49
- }
50
31
 
51
- res.setHeader('WWW-Authenticate', 'Bearer realm="Core API"')
52
- res.status(401).send('Authentication required.')
53
- return false
54
- }
55
- }
56
32
 
57
33
  constructor(params: AuthParameters = {}) {
58
34
  super(params)
@@ -246,4 +222,20 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
246
222
  return data
247
223
  }
248
224
  }
225
+
226
+ /**
227
+ * Initiates password recovery/reset process for a user.
228
+ *
229
+ * @param email - The user email.
230
+ * @param redirectTo - Optional redirect destination.
231
+ */
232
+ async recoverPassword(email: string, redirectTo?: string) {
233
+ const { data, error } = await this._client.auth.resetPasswordForEmail(email, {
234
+ redirectTo,
235
+ })
236
+ if (error) {
237
+ throw new Error(error.message)
238
+ }
239
+ return data
240
+ }
249
241
  }