@quatrain/auth-supabase 1.1.11 → 1.1.13
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.
|
@@ -10,12 +10,13 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
10
10
|
*/
|
|
11
11
|
register(user: User): Promise<any>;
|
|
12
12
|
getAuthToken(bearer: string): Promise<any>;
|
|
13
|
+
refreshToken(refreshToken: string): Promise<any>;
|
|
13
14
|
revokeAuthToken(token: string): Promise<void>;
|
|
14
15
|
signup(login: string, password: string): Promise<false | {
|
|
15
16
|
user: any;
|
|
16
17
|
session: any;
|
|
17
18
|
}>;
|
|
18
|
-
signout(
|
|
19
|
+
signout(): Promise<any>;
|
|
19
20
|
update(user: User, updatable: any): Promise<any>;
|
|
20
21
|
delete(user: User): Promise<any>;
|
|
21
22
|
setCustomUserClaims(id: string, claims: any): Promise<any>;
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -12,6 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
35
|
exports.SupabaseAuthAdapter = void 0;
|
|
13
36
|
const auth_1 = require("@quatrain/auth");
|
|
14
37
|
const supabase_js_1 = require("@supabase/supabase-js");
|
|
38
|
+
const nativeFetch = __importStar(require("node-fetch-native"));
|
|
15
39
|
// Create a single supabase client for interacting with your database
|
|
16
40
|
class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
17
41
|
constructor(params = {}) {
|
|
@@ -31,22 +55,24 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
31
55
|
register(user) {
|
|
32
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
57
|
try {
|
|
34
|
-
const { name: displayName, email, phone: phoneNumber, password,
|
|
35
|
-
|
|
36
|
-
} = user._;
|
|
37
|
-
auth_1.Auth.log(`[SAA] Adding user '${displayName}'`);
|
|
58
|
+
const { name: displayName, email, phone: phoneNumber, password, } = user._;
|
|
59
|
+
auth_1.Auth.info(`[SAA] Adding user '${displayName}'`);
|
|
38
60
|
const { data, error } = yield this._client.auth.admin.createUser({
|
|
39
61
|
email,
|
|
40
62
|
password,
|
|
63
|
+
email_confirm: false, // TODO move to params
|
|
41
64
|
});
|
|
42
65
|
if (error) {
|
|
43
|
-
|
|
66
|
+
auth_1.Auth.error(error.message);
|
|
67
|
+
if (error.code === 'email_exists') {
|
|
68
|
+
throw new auth_1.AuthenticationError(auth_1.Auth.ERROR_EMAIL_EXISTS);
|
|
69
|
+
}
|
|
44
70
|
throw new Error(error);
|
|
45
71
|
}
|
|
46
72
|
return data.user;
|
|
47
73
|
}
|
|
48
74
|
catch (err) {
|
|
49
|
-
|
|
75
|
+
auth_1.Auth.error(err);
|
|
50
76
|
throw new auth_1.AuthenticationError(err.message);
|
|
51
77
|
}
|
|
52
78
|
});
|
|
@@ -60,10 +86,26 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
60
86
|
throw new Error('Unable to retrieve auth token from Supabase');
|
|
61
87
|
});
|
|
62
88
|
}
|
|
89
|
+
refreshToken(refreshToken) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const url = `${this._params.config.supabaseUrl}/auth/v1/token?grant_type=refresh_token`;
|
|
92
|
+
const response = yield nativeFetch.fetch(url, {
|
|
93
|
+
method: 'POST',
|
|
94
|
+
headers: {
|
|
95
|
+
apikey: this._params.config.supabaseKey,
|
|
96
|
+
},
|
|
97
|
+
body: JSON.stringify({
|
|
98
|
+
refresh_token: refreshToken,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
const data = response.json();
|
|
102
|
+
return data;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
63
105
|
revokeAuthToken(token) {
|
|
64
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
107
|
// Careful, this only delete tokens on client side, not on server side
|
|
66
|
-
const { error } = yield this.
|
|
108
|
+
const { error } = yield this.signout();
|
|
67
109
|
});
|
|
68
110
|
}
|
|
69
111
|
signup(login, password) {
|
|
@@ -79,15 +121,22 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
79
121
|
return { user: data.user, session: data.session };
|
|
80
122
|
});
|
|
81
123
|
}
|
|
82
|
-
signout(
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
signout() {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const { data, error } = yield this._client.auth.signOut();
|
|
127
|
+
if (error !== null) {
|
|
128
|
+
auth_1.Auth.error(error);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
});
|
|
84
133
|
}
|
|
85
134
|
update(user, updatable) {
|
|
86
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
auth_1.Auth.
|
|
136
|
+
auth_1.Auth.debug('auth data to update', JSON.stringify(updatable));
|
|
88
137
|
try {
|
|
89
138
|
if (Object.keys(updatable).length > 0) {
|
|
90
|
-
auth_1.Auth.
|
|
139
|
+
auth_1.Auth.info(`Updating ${updatable.displayName} Auth record`);
|
|
91
140
|
const { data, error } = yield this._client.auth.admin.updateUserById(user.uid, updatable);
|
|
92
141
|
if (error !== null) {
|
|
93
142
|
auth_1.Auth.log(error);
|
|
@@ -104,13 +153,13 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
|
104
153
|
}
|
|
105
154
|
setCustomUserClaims(id, claims) {
|
|
106
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
auth_1.Auth.
|
|
156
|
+
auth_1.Auth.debug(`Updating user ${id} with claims ${JSON.stringify(claims)}`);
|
|
108
157
|
const { data, error } = yield this._client.auth.admin.updateUserById(id, {
|
|
109
158
|
user_metadata: claims,
|
|
110
159
|
});
|
|
111
160
|
console.log(data, error);
|
|
112
161
|
if (error) {
|
|
113
|
-
throw new
|
|
162
|
+
throw new auth_1.AuthenticationError(error);
|
|
114
163
|
}
|
|
115
164
|
else {
|
|
116
165
|
return data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/auth-supabase",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
],
|
|
11
11
|
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@quatrain/auth": "^1.1.
|
|
14
|
-
"@supabase/supabase-js": "^2.
|
|
13
|
+
"@quatrain/auth": "^1.1.16",
|
|
14
|
+
"@supabase/supabase-js": "^2.48.1",
|
|
15
|
+
"node-fetch-native": "^1.6.4"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@tsconfig/recommended": "^1.0.1",
|
|
@@ -26,12 +27,14 @@
|
|
|
26
27
|
"typescript": "^5.1.5"
|
|
27
28
|
},
|
|
28
29
|
"scripts": {
|
|
29
|
-
"pretest": "tsc",
|
|
30
|
-
"test": "clear && firebase emulators:exec 'jest -i --verbose'",
|
|
31
30
|
"test-ci": "jest --runInBand",
|
|
32
31
|
"build": "tsc",
|
|
33
32
|
"wbuild": "tsc --watch",
|
|
34
33
|
"bump-to": "yarn version",
|
|
35
|
-
"
|
|
34
|
+
"hash": "node ../../bin/hashFolder.js",
|
|
35
|
+
"hash:persist": "yarn hash > .hash_latest.txt",
|
|
36
|
+
"hash:compare": "yarn hash > .hash_newest.txt && cmp -s .hash_latest.txt .hash_newest.txt",
|
|
37
|
+
"publish": "yarn hash:compare || yarn publish:process",
|
|
38
|
+
"publish:process": "yarn version patch && yarn build && yarn npm publish --access public && yarn hash:persist"
|
|
36
39
|
}
|
|
37
40
|
}
|