@quatrain/auth-supabase 1.1.12 → 1.1.14

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.
@@ -16,7 +16,7 @@ export declare class SupabaseAuthAdapter extends AbstractAuthAdapter {
16
16
  user: any;
17
17
  session: any;
18
18
  }>;
19
- signout(user: User): Promise<any>;
19
+ signout(): Promise<any>;
20
20
  update(user: User, updatable: any): Promise<any>;
21
21
  delete(user: User): Promise<any>;
22
22
  setCustomUserClaims(id: string, claims: any): Promise<any>;
@@ -55,22 +55,24 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
55
55
  register(user) {
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  try {
58
- const { name: displayName, email, phone: phoneNumber, password,
59
- //disabled = false,
60
- } = user._;
61
- 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}'`);
62
60
  const { data, error } = yield this._client.auth.admin.createUser({
63
61
  email,
64
62
  password,
63
+ email_confirm: true, // TODO move to params
65
64
  });
66
65
  if (error) {
67
- console.log(error);
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
+ }
68
70
  throw new Error(error);
69
71
  }
70
72
  return data.user;
71
73
  }
72
74
  catch (err) {
73
- console.log(err);
75
+ auth_1.Auth.error(err);
74
76
  throw new auth_1.AuthenticationError(err.message);
75
77
  }
76
78
  });
@@ -103,7 +105,7 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
103
105
  revokeAuthToken(token) {
104
106
  return __awaiter(this, void 0, void 0, function* () {
105
107
  // Careful, this only delete tokens on client side, not on server side
106
- const { error } = yield this._client.auth.signOut();
108
+ const { error } = yield this.signout();
107
109
  });
108
110
  }
109
111
  signup(login, password) {
@@ -119,15 +121,22 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
119
121
  return { user: data.user, session: data.session };
120
122
  });
121
123
  }
122
- signout(user) {
123
- 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
+ });
124
133
  }
125
134
  update(user, updatable) {
126
135
  return __awaiter(this, void 0, void 0, function* () {
127
- auth_1.Auth.log('auth data to update', JSON.stringify(updatable));
136
+ auth_1.Auth.debug('auth data to update', JSON.stringify(updatable));
128
137
  try {
129
138
  if (Object.keys(updatable).length > 0) {
130
- auth_1.Auth.log(`Updating ${updatable.displayName} Auth record`);
139
+ auth_1.Auth.info(`Updating ${updatable.displayName} Auth record`);
131
140
  const { data, error } = yield this._client.auth.admin.updateUserById(user.uid, updatable);
132
141
  if (error !== null) {
133
142
  auth_1.Auth.log(error);
@@ -144,13 +153,13 @@ class SupabaseAuthAdapter extends auth_1.AbstractAuthAdapter {
144
153
  }
145
154
  setCustomUserClaims(id, claims) {
146
155
  return __awaiter(this, void 0, void 0, function* () {
147
- auth_1.Auth.log(`Updating user ${id} with claims ${JSON.stringify(claims)}`);
156
+ auth_1.Auth.debug(`Updating user ${id} with claims ${JSON.stringify(claims)}`);
148
157
  const { data, error } = yield this._client.auth.admin.updateUserById(id, {
149
158
  user_metadata: claims,
150
159
  });
151
160
  console.log(data, error);
152
161
  if (error) {
153
- throw new Error(error);
162
+ throw new auth_1.AuthenticationError(error);
154
163
  }
155
164
  else {
156
165
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/auth-supabase",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
12
  "dependencies": {
13
- "@quatrain/auth": "^1.1.14",
14
- "@supabase/supabase-js": "^2.45.1",
13
+ "@quatrain/auth": "^1.1.16",
14
+ "@supabase/supabase-js": "^2.48.1",
15
15
  "node-fetch-native": "^1.6.4"
16
16
  },
17
17
  "devDependencies": {