@quatrain/auth-firebase 0.0.1 → 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.
@@ -1,8 +1,14 @@
1
- import { AbstractAuthAdapter, User } from '@quatrain/core';
1
+ import { AbstractAuthAdapter, User, AuthParameters } from '@quatrain/core';
2
2
  import { UpdateRequest } from 'firebase-admin/auth';
3
3
  export declare class FirebaseAuthAdapter extends AbstractAuthAdapter {
4
- signin(user: User): Promise<User>;
5
- getAuthToken(token: string): Promise<import("firebase-admin/auth").DecodedIdToken>;
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<string>;
11
+ getAuthToken(bearer: string): Promise<import("firebase-admin/auth").DecodedIdToken>;
6
12
  signup(login: string, password: string): Promise<void>;
7
13
  signout(user: User): Promise<any>;
8
14
  update(user: User, updatable: UpdateRequest): Promise<any>;
@@ -11,10 +11,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FirebaseAuthAdapter = void 0;
13
13
  const core_1 = require("@quatrain/core");
14
- const authentication_1 = require("@quatrain/core/lib/authentication");
15
14
  const auth_1 = require("firebase-admin/auth");
15
+ const app_1 = require("firebase-admin/app");
16
16
  class FirebaseAuthAdapter extends core_1.AbstractAuthAdapter {
17
- signin(user) {
17
+ constructor(params = {}) {
18
+ super(params);
19
+ if ((0, app_1.getApps)().length === 0) {
20
+ (0, app_1.initializeApp)(params.config);
21
+ }
22
+ }
23
+ /**
24
+ * Register new user in authentication
25
+ * @param user
26
+ * @returns user unique id
27
+ */
28
+ register(user) {
18
29
  return __awaiter(this, void 0, void 0, function* () {
19
30
  try {
20
31
  const { name: displayName, email, phone: phoneNumber, password, disabled = false, } = user._;
@@ -27,17 +38,17 @@ class FirebaseAuthAdapter extends core_1.AbstractAuthAdapter {
27
38
  displayName,
28
39
  };
29
40
  core_1.Core.log(`[FAA] Adding user '${displayName}'`);
30
- yield (0, auth_1.getAuth)().createUser(authData);
31
- return user;
41
+ const userRecord = yield (0, auth_1.getAuth)().createUser(authData);
42
+ return userRecord.uid;
32
43
  }
33
44
  catch (err) {
34
- throw new authentication_1.AuthenticationError(err.message);
45
+ throw new core_1.AuthenticationError(err.message);
35
46
  }
36
47
  });
37
48
  }
38
- getAuthToken(token) {
49
+ getAuthToken(bearer) {
39
50
  return __awaiter(this, void 0, void 0, function* () {
40
- return yield (0, auth_1.getAuth)().verifyIdToken(token);
51
+ return yield (0, auth_1.getAuth)().verifyIdToken(bearer);
41
52
  });
42
53
  }
43
54
  signup(login, password) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-firebase",
3
- "version": "0.0.1",
3
+ "version": "1.0.0-beta1",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -9,8 +9,10 @@
9
9
  "README.md"
10
10
  ],
11
11
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
+ "peerDependencies": {
13
+ "@quatrain/core": "^1.0.0-beta2"
14
+ },
12
15
  "dependencies": {
13
- "@quatrain/core": "^1.0.0-beta2",
14
16
  "firebase-admin": "^12.0.0"
15
17
  },
16
18
  "devDependencies": {
@@ -23,7 +25,7 @@
23
25
  "trace-unhandled": "^2.0.1",
24
26
  "ts-jest": "^27.1.2",
25
27
  "ts-node": "^10.9.1",
26
- "typescript": "^4.8.3"
28
+ "typescript": "^5.1.5"
27
29
  },
28
30
  "scripts": {
29
31
  "pretest": "tsc",