@quatrain/auth-supabase 1.0.0-beta1
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.
- package/lib/SupabaseAuthAdapter.d.ts +16 -0
- package/lib/SupabaseAuthAdapter.js +76 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +5 -0
- package/package.json +39 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AbstractAuthAdapter, User, AuthParameters } from '@quatrain/core';
|
|
2
|
+
export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
|
|
3
|
+
protected _client: any;
|
|
4
|
+
constructor(params?: AuthParameters);
|
|
5
|
+
/**
|
|
6
|
+
* Register new user in authentication
|
|
7
|
+
* @param user
|
|
8
|
+
* @returns user unique id
|
|
9
|
+
*/
|
|
10
|
+
register(user: User): Promise<void>;
|
|
11
|
+
getAuthToken(bearer: string): Promise<any>;
|
|
12
|
+
signup(login: string, password: string): Promise<void>;
|
|
13
|
+
signout(user: User): Promise<any>;
|
|
14
|
+
update(user: User, updatable: any): Promise<any>;
|
|
15
|
+
delete(user: User): Promise<any>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SupabaseAuthAdapter = void 0;
|
|
13
|
+
const core_1 = require("@quatrain/core");
|
|
14
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
15
|
+
// Create a single supabase client for interacting with your database
|
|
16
|
+
class SupabaseAuthAdapter extends core_1.AbstractAuthAdapter {
|
|
17
|
+
constructor(params = {}) {
|
|
18
|
+
super(params);
|
|
19
|
+
this._client = (0, supabase_js_1.createClient)(params.config.supabaseUrl, params.config.supabaseKey);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register new user in authentication
|
|
23
|
+
* @param user
|
|
24
|
+
* @returns user unique id
|
|
25
|
+
*/
|
|
26
|
+
register(user) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
const { name: displayName, email, phone: phoneNumber, password, disabled = false, } = user._;
|
|
30
|
+
const authData = {
|
|
31
|
+
uid: user.uid,
|
|
32
|
+
email,
|
|
33
|
+
phoneNumber,
|
|
34
|
+
password,
|
|
35
|
+
disabled,
|
|
36
|
+
displayName,
|
|
37
|
+
};
|
|
38
|
+
core_1.Core.log(`[SAA] Adding user '${displayName}'`);
|
|
39
|
+
// const userRecord = await getAuth().createUser(authData)
|
|
40
|
+
return; // userRecord.uid
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
throw new core_1.AuthenticationError(err.message);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
getAuthToken(bearer) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this._client.auth.getUser(bearer);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
signup(login, password) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
54
|
+
}
|
|
55
|
+
signout(user) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
57
|
+
}
|
|
58
|
+
update(user, updatable) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
console.log('auth data to update', JSON.stringify(updatable));
|
|
61
|
+
try {
|
|
62
|
+
if (Object.keys(updatable).length > 0) {
|
|
63
|
+
console.log(`Updating ${updatable.displayName} Auth record`);
|
|
64
|
+
// await getAuth().updateUser(user.uid, updatable)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (e) { }
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
delete(user) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
// return await getAuth().deleteUser(user.uid)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.SupabaseAuthAdapter = SupabaseAuthAdapter;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SupabaseAuthAdapter = void 0;
|
|
4
|
+
const SupabaseAuthAdapter_1 = require("./SupabaseAuthAdapter");
|
|
5
|
+
Object.defineProperty(exports, "SupabaseAuthAdapter", { enumerable: true, get: function () { return SupabaseAuthAdapter_1.SupabaseAuthAdapter; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quatrain/auth-supabase",
|
|
3
|
+
"version": "1.0.0-beta1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@quatrain/core": "^1.0.0-beta2"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@supabase/supabase-js": "^2.42.4",
|
|
17
|
+
"firebase-admin": "^12.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@faker-js/faker": "^7.6.0",
|
|
21
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
22
|
+
"@types/jest": "^27.0.3",
|
|
23
|
+
"jest": "^27.4.7",
|
|
24
|
+
"jest-node-exports-resolver": "^1.1.6",
|
|
25
|
+
"jest-serial-runner": "^1.2.1",
|
|
26
|
+
"trace-unhandled": "^2.0.1",
|
|
27
|
+
"ts-jest": "^27.1.2",
|
|
28
|
+
"ts-node": "^10.9.1",
|
|
29
|
+
"typescript": "^5.1.5"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"pretest": "tsc",
|
|
33
|
+
"test": "clear && firebase emulators:exec 'jest -i --verbose'",
|
|
34
|
+
"test-ci": "jest --runInBand",
|
|
35
|
+
"build": "tsc --watch",
|
|
36
|
+
"prepush": "tsc",
|
|
37
|
+
"push": "yarn publish --access public"
|
|
38
|
+
}
|
|
39
|
+
}
|