@quatrain/auth-firebase 0.0.1 → 1.1.5

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,10 +1,19 @@
1
- import { AbstractAuthAdapter, User } from '@quatrain/core';
1
+ import { User } from '@quatrain/backend';
2
+ import { AbstractAuthAdapter, AuthParameters } from '@quatrain/auth';
2
3
  import { UpdateRequest } from 'firebase-admin/auth';
3
4
  export declare class FirebaseAuthAdapter extends AbstractAuthAdapter {
4
- signin(user: User): Promise<User>;
5
- getAuthToken(token: string): Promise<import("firebase-admin/auth").DecodedIdToken>;
5
+ constructor(params?: AuthParameters);
6
+ /**
7
+ * Register new user in authentication
8
+ * @param user
9
+ * @returns user unique id
10
+ */
11
+ register(user: User): Promise<string>;
12
+ getAuthToken(bearer: string): Promise<import("firebase-admin/auth").DecodedIdToken>;
6
13
  signup(login: string, password: string): Promise<void>;
7
14
  signout(user: User): Promise<any>;
8
15
  update(user: User, updatable: UpdateRequest): Promise<any>;
9
16
  delete(user: User): Promise<any>;
17
+ revokeAuthToken(token: string): Promise<void>;
18
+ setCustomUserClaims(id: string, claims: any): Promise<void>;
10
19
  }
@@ -10,11 +10,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FirebaseAuthAdapter = void 0;
13
- const core_1 = require("@quatrain/core");
14
- const authentication_1 = require("@quatrain/core/lib/authentication");
15
- const auth_1 = require("firebase-admin/auth");
16
- class FirebaseAuthAdapter extends core_1.AbstractAuthAdapter {
17
- signin(user) {
13
+ const auth_1 = require("@quatrain/auth");
14
+ const auth_2 = require("firebase-admin/auth");
15
+ const app_1 = require("firebase-admin/app");
16
+ class FirebaseAuthAdapter extends auth_1.AbstractAuthAdapter {
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._;
@@ -26,18 +37,18 @@ class FirebaseAuthAdapter extends core_1.AbstractAuthAdapter {
26
37
  disabled,
27
38
  displayName,
28
39
  };
29
- core_1.Core.log(`[FAA] Adding user '${displayName}'`);
30
- yield (0, auth_1.getAuth)().createUser(authData);
31
- return user;
40
+ auth_1.Auth.log(`[FAA] Adding user '${displayName}'`);
41
+ const userRecord = yield (0, auth_2.getAuth)().createUser(authData);
42
+ return userRecord.uid;
32
43
  }
33
44
  catch (err) {
34
- throw new authentication_1.AuthenticationError(err.message);
45
+ throw new auth_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_2.getAuth)().verifyIdToken(bearer);
41
52
  });
42
53
  }
43
54
  signup(login, password) {
@@ -48,11 +59,11 @@ class FirebaseAuthAdapter extends core_1.AbstractAuthAdapter {
48
59
  }
49
60
  update(user, updatable) {
50
61
  return __awaiter(this, void 0, void 0, function* () {
51
- console.log('auth data to update', JSON.stringify(updatable));
62
+ auth_1.Auth.log('auth data to update', JSON.stringify(updatable));
52
63
  try {
53
64
  if (Object.keys(updatable).length > 0) {
54
- console.log(`Updating ${updatable.displayName} Auth record`);
55
- yield (0, auth_1.getAuth)().updateUser(user.uid, updatable);
65
+ auth_1.Auth.log(`Updating ${updatable.displayName} Auth record`);
66
+ yield (0, auth_2.getAuth)().updateUser(user.uid, updatable);
56
67
  }
57
68
  }
58
69
  catch (e) { }
@@ -60,8 +71,14 @@ class FirebaseAuthAdapter extends core_1.AbstractAuthAdapter {
60
71
  }
61
72
  delete(user) {
62
73
  return __awaiter(this, void 0, void 0, function* () {
63
- return yield (0, auth_1.getAuth)().deleteUser(user.uid);
74
+ return yield (0, auth_2.getAuth)().deleteUser(user.uid);
64
75
  });
65
76
  }
77
+ revokeAuthToken(token) {
78
+ return __awaiter(this, void 0, void 0, function* () { });
79
+ }
80
+ setCustomUserClaims(id, claims) {
81
+ return __awaiter(this, void 0, void 0, function* () { });
82
+ }
66
83
  }
67
84
  exports.FirebaseAuthAdapter = FirebaseAuthAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-firebase",
3
- "version": "0.0.1",
3
+ "version": "1.1.5",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -9,28 +9,33 @@
9
9
  "README.md"
10
10
  ],
11
11
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
+ "peerDependencies": {
13
+ "@quatrain/core": "^1.1.5"
14
+ },
12
15
  "dependencies": {
13
- "@quatrain/core": "^1.0.0-beta2",
14
- "firebase-admin": "^12.0.0"
16
+ "@quatrain/auth": "^1.1.5",
17
+ "firebase-admin": "^13.0.1"
15
18
  },
16
19
  "devDependencies": {
17
20
  "@faker-js/faker": "^7.6.0",
18
21
  "@tsconfig/recommended": "^1.0.1",
19
22
  "@types/jest": "^27.0.3",
23
+ "@types/node": "^22.10.1",
20
24
  "jest": "^27.4.7",
21
25
  "jest-node-exports-resolver": "^1.1.6",
22
26
  "jest-serial-runner": "^1.2.1",
23
27
  "trace-unhandled": "^2.0.1",
24
28
  "ts-jest": "^27.1.2",
25
29
  "ts-node": "^10.9.1",
26
- "typescript": "^4.8.3"
30
+ "typescript": "^5.1.5"
27
31
  },
28
32
  "scripts": {
29
33
  "pretest": "tsc",
30
34
  "test": "clear && firebase emulators:exec 'jest -i --verbose'",
31
35
  "test-ci": "jest --runInBand",
32
- "build": "tsc --watch",
33
- "prepush": "tsc",
34
- "push": "yarn publish --access public"
36
+ "build": "tsc",
37
+ "wbuild": "tsc --watch",
38
+ "bump-to": "yarn version",
39
+ "publish": "yarn build && yarn npm publish --access public"
35
40
  }
36
- }
41
+ }