@quatrain/auth-supabase 1.0.0-beta2 → 1.0.0
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,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { User } from '@quatrain/core';
|
|
2
|
+
import { AbstractAuthAdapter, AuthParameters } from '@quatrain/auth';
|
|
2
3
|
export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
3
4
|
protected _client: any;
|
|
4
5
|
constructor(params?: AuthParameters);
|
|
@@ -7,7 +8,7 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
|
7
8
|
* @param user
|
|
8
9
|
* @returns user unique id
|
|
9
10
|
*/
|
|
10
|
-
register(user: User): Promise<
|
|
11
|
+
register(user: User): Promise<any>;
|
|
11
12
|
getAuthToken(bearer: string): Promise<any>;
|
|
12
13
|
signup(login: string, password: string): Promise<void>;
|
|
13
14
|
signout(user: User): Promise<any>;
|
|
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SupabaseAuthAdapter = void 0;
|
|
13
|
-
const
|
|
13
|
+
const auth_1 = require("@quatrain/auth");
|
|
14
14
|
const supabase_js_1 = require("@supabase/supabase-js");
|
|
15
15
|
// Create a single supabase client for interacting with your database
|
|
16
|
-
class SupabaseAuthAdapter extends
|
|
16
|
+
class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
|
|
17
17
|
constructor(params = {}) {
|
|
18
18
|
super(params);
|
|
19
19
|
this._client = (0, supabase_js_1.createClient)(params.config.supabaseUrl, params.config.supabaseKey);
|
|
@@ -27,26 +27,29 @@ class SupabaseAuthAdapter extends core_1.AbstractAuthAdapter {
|
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
try {
|
|
29
29
|
const { name: displayName, email, phone: phoneNumber, password, disabled = false, } = user._;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
auth_1.Auth.log(`[SAA] Adding user '${displayName}'`);
|
|
31
|
+
const { data, error } = yield this._client.auth.signUp({
|
|
32
32
|
email,
|
|
33
|
-
phoneNumber,
|
|
34
33
|
password,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return; // userRecord.uid
|
|
34
|
+
});
|
|
35
|
+
if (error) {
|
|
36
|
+
throw new Error(error);
|
|
37
|
+
}
|
|
38
|
+
return data.user;
|
|
41
39
|
}
|
|
42
40
|
catch (err) {
|
|
43
|
-
|
|
41
|
+
console.log(err);
|
|
42
|
+
throw new auth_1.AuthenticationError(err.message);
|
|
44
43
|
}
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
46
|
getAuthToken(bearer) {
|
|
48
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
48
|
+
const token = yield this._client.auth.getUser(bearer);
|
|
49
|
+
if (token.data && token.data.user) {
|
|
50
|
+
return token.data.user;
|
|
51
|
+
}
|
|
52
|
+
throw new Error('Unable to retrieve auth token from Supabase');
|
|
50
53
|
});
|
|
51
54
|
}
|
|
52
55
|
signup(login, password) {
|
|
@@ -57,10 +60,10 @@ class SupabaseAuthAdapter extends core_1.AbstractAuthAdapter {
|
|
|
57
60
|
}
|
|
58
61
|
update(user, updatable) {
|
|
59
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
|
|
63
|
+
auth_1.Auth.log('auth data to update', JSON.stringify(updatable));
|
|
61
64
|
try {
|
|
62
65
|
if (Object.keys(updatable).length > 0) {
|
|
63
|
-
|
|
66
|
+
auth_1.Auth.log(`Updating ${updatable.displayName} Auth record`);
|
|
64
67
|
// await getAuth().updateUser(user.uid, updatable)
|
|
65
68
|
}
|
|
66
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatrain/auth-supabase",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"@quatrain/core": "^1.0.0-beta2"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@quatrain/auth": "^1.0.0",
|
|
16
17
|
"@supabase/supabase-js": "^2.42.4"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|