@quatrain/auth-supabase 1.2.10-pr25.6987 → 1.2.11
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.
|
@@ -25,7 +25,7 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
25
25
|
*
|
|
26
26
|
* @param bearer - Raw JWT string.
|
|
27
27
|
* @returns The decoded user object.
|
|
28
|
-
* @throws {
|
|
28
|
+
* @throws {AuthenticationError} If verification fails.
|
|
29
29
|
*/
|
|
30
30
|
getAuthToken(bearer: string): Promise<any>;
|
|
31
31
|
/**
|
|
@@ -74,15 +74,17 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
74
74
|
*
|
|
75
75
|
* @param bearer - Raw JWT string.
|
|
76
76
|
* @returns The decoded user object.
|
|
77
|
-
* @throws {
|
|
77
|
+
* @throws {AuthenticationError} If verification fails.
|
|
78
78
|
*/
|
|
79
79
|
getAuthToken(bearer) {
|
|
80
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
var _a;
|
|
81
82
|
const token = yield this._client.auth.getUser(bearer);
|
|
82
83
|
if (token.data && token.data.user) {
|
|
83
84
|
return token.data.user;
|
|
84
85
|
}
|
|
85
|
-
|
|
86
|
+
const reason = ((_a = token.error) === null || _a === void 0 ? void 0 : _a.message) ? `: ${token.error.message}` : '';
|
|
87
|
+
throw new auth_1.AuthenticationError(`Unable to retrieve auth token from Supabase${reason}`);
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
@@ -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.
|
|
3
|
+
"version": "1.2.11",
|
|
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.8",
|
|
23
|
+
"@quatrain/auth": "^1.2.12",
|
|
24
|
+
"@quatrain/backend": "^1.2.20",
|
|
25
25
|
"@supabase/supabase-js": "^2.108.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -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()', () => {
|
|
@@ -85,14 +85,15 @@ export class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
85
85
|
*
|
|
86
86
|
* @param bearer - Raw JWT string.
|
|
87
87
|
* @returns The decoded user object.
|
|
88
|
-
* @throws {
|
|
88
|
+
* @throws {AuthenticationError} If verification fails.
|
|
89
89
|
*/
|
|
90
90
|
async getAuthToken(bearer: string) {
|
|
91
91
|
const token = await this._client.auth.getUser(bearer)
|
|
92
92
|
if (token.data && token.data.user) {
|
|
93
93
|
return token.data.user
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
const reason = token.error?.message ? `: ${token.error.message}` : ''
|
|
96
|
+
throw new AuthenticationError(`Unable to retrieve auth token from Supabase${reason}`)
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
/**
|