supaapps-auth 2.0.0-rc.7 → 2.0.0-rc.8

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.
@@ -11,15 +11,15 @@ export declare class AuthManager {
11
11
  private tokenToPayload;
12
12
  private toBase64Url;
13
13
  private generatePKCEPair;
14
- refreshAccessToken(isInitilization?: boolean): Promise<string>;
14
+ refreshAccessToken(isInitialization?: boolean): Promise<string>;
15
15
  checkAccessToken(isInitilization?: boolean): Promise<string>;
16
16
  private isTokenExpired;
17
17
  mustBeLoggedIn(): Promise<void>;
18
18
  getLoginWithGoogleUri(): string;
19
19
  isLoggedIn(): Promise<boolean>;
20
20
  getAccessToken(mustBeLoggedIn?: boolean): Promise<string>;
21
- verifyEmail(email: string, code: string): Promise<boolean>;
22
- doPassReset(email: string, code: string, newPassword: string): Promise<boolean>;
21
+ verifyEmail(email: string, token: string): Promise<boolean>;
22
+ doPassReset(email: string, token: string, newPassword: string): Promise<boolean>;
23
23
  changeEmail(email: string): Promise<boolean>;
24
24
  initPasswordReset(email: string): Promise<boolean>;
25
25
  changePassword(oldPassword: string, newPassword: string, email: string): Promise<boolean>;
@@ -63,7 +63,7 @@ class AuthManager {
63
63
  return { verifier, challenge };
64
64
  }
65
65
  refreshAccessToken() {
66
- return __awaiter(this, arguments, void 0, function* (isInitilization = false) {
66
+ return __awaiter(this, arguments, void 0, function* (isInitialization = false) {
67
67
  try {
68
68
  const refreshToken = localStorage.getItem('refresh_token');
69
69
  if (!refreshToken) {
@@ -79,7 +79,7 @@ class AuthManager {
79
79
  console.error(`Refresh token error, logging out: ${error}`);
80
80
  localStorage.removeItem('access_token');
81
81
  localStorage.removeItem('refresh_token');
82
- if (!isInitilization) {
82
+ if (!isInitialization) {
83
83
  // throw refresh fail only if not initialization
84
84
  this.onStateChange({ type: types_1.AuthEventType.REFRESH_FAILED });
85
85
  }
@@ -139,12 +139,12 @@ class AuthManager {
139
139
  }
140
140
  });
141
141
  }
142
- verifyEmail(email, code) {
142
+ verifyEmail(email, token) {
143
143
  return __awaiter(this, void 0, void 0, function* () {
144
144
  const response = yield axios_1.default.post(`${this.authServer}auth/email/verify`, {
145
145
  realm_name: this.realmName,
146
146
  email,
147
- code,
147
+ token,
148
148
  });
149
149
  if (response.data.error || response.data.errors) {
150
150
  throw new Error(response.data.error || response.data.message);
@@ -152,11 +152,13 @@ class AuthManager {
152
152
  return response.status === 200;
153
153
  });
154
154
  }
155
- doPassReset(email, code, newPassword) {
155
+ doPassReset(email, token, newPassword) {
156
156
  return __awaiter(this, void 0, void 0, function* () {
157
157
  const response = yield axios_1.default.post(`${this.authServer}auth/email/do_pass_reset`, {
158
158
  realm_name: this.realmName,
159
159
  email,
160
+ token,
161
+ new_password: newPassword,
160
162
  });
161
163
  if (response.data.error || response.data.errors) {
162
164
  throw new Error(response.data.error || response.data.message);
@@ -306,23 +308,23 @@ class AuthManager {
306
308
  throw new Error('Not a valid jwt token');
307
309
  }
308
310
  const userToken = {
309
- id: decodedToken['id'],
310
- iss: decodedToken['iss'],
311
- sub: parseInt(decodedToken['sub']),
312
- first_name: decodedToken['first_name'],
313
- last_name: decodedToken['last_name'],
314
- email: decodedToken['email'],
315
- aud: decodedToken['aud'],
316
- iat: decodedToken['iat'],
317
- exp: decodedToken['exp'],
318
- scopes: decodedToken['scopes'],
319
- realm: decodedToken['realm'],
311
+ id: decodedToken.id,
312
+ iss: decodedToken.iss,
313
+ sub: typeof decodedToken.sub === 'string' ? parseInt(decodedToken.sub) : decodedToken.sub,
314
+ first_name: decodedToken.first_name,
315
+ last_name: decodedToken.last_name,
316
+ email: decodedToken.email,
317
+ aud: decodedToken.aud,
318
+ iat: decodedToken.iat,
319
+ exp: decodedToken.exp,
320
+ scopes: decodedToken.scopes,
321
+ realm: decodedToken.realm,
320
322
  };
321
323
  const { data: publicKey } = yield axios_1.default.get(`${authServer}public/public_key`);
322
324
  const { data: algo } = yield axios_1.default.get(`${authServer}public/algo`);
323
325
  (0, jsonwebtoken_1.verify)(bearerToken, publicKey, { algorithms: [algo] });
324
326
  const { data: revokedIds } = yield axios_1.default.get(`${authServer}public/revoked_ids`);
325
- if (revokedIds.includes(decodedToken['id'])) {
327
+ if (revokedIds.includes(decodedToken.id)) {
326
328
  throw new Error('Token is revoked');
327
329
  }
328
330
  return userToken;
package/dist/types.d.ts CHANGED
@@ -10,7 +10,7 @@ export declare enum AuthEventType {
10
10
  export interface UserTokenPayload {
11
11
  id: number;
12
12
  iss: string;
13
- sub: number;
13
+ sub: number | string;
14
14
  first_name: string;
15
15
  last_name: string;
16
16
  email: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supaapps-auth",
3
- "version": "2.0.0-rc.7",
3
+ "version": "2.0.0-rc.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "@typescript-eslint/eslint-plugin": "^6.21.0",
26
26
  "@typescript-eslint/parser": "^6.21.0",
27
27
  "axios-mock-adapter": "^1.22.0",
28
- "eslint": "^8.57.0",
28
+ "eslint": "^8.57.1",
29
29
  "eslint-config-airbnb-base": "^15.0.0",
30
30
  "eslint-config-airbnb-typescript": "^17.1.0",
31
31
  "eslint-config-next": "^13.5.6",
@@ -95,7 +95,7 @@ export class AuthManager {
95
95
  return { verifier, challenge };
96
96
  }
97
97
 
98
- public async refreshAccessToken(isInitilization: boolean = false): Promise<string> {
98
+ public async refreshAccessToken(isInitialization: boolean = false): Promise<string> {
99
99
  try {
100
100
  const refreshToken = localStorage.getItem('refresh_token');
101
101
  if (!refreshToken) {
@@ -114,7 +114,7 @@ export class AuthManager {
114
114
  console.error(`Refresh token error, logging out: ${error}`);
115
115
  localStorage.removeItem('access_token');
116
116
  localStorage.removeItem('refresh_token');
117
- if (!isInitilization) {
117
+ if (!isInitialization) {
118
118
  // throw refresh fail only if not initialization
119
119
  this.onStateChange({ type: AuthEventType.REFRESH_FAILED });
120
120
  }
@@ -170,13 +170,13 @@ export class AuthManager {
170
170
  }
171
171
  }
172
172
 
173
- public async verifyEmail(email: string, code: string): Promise<boolean> {
173
+ public async verifyEmail(email: string, token: string): Promise<boolean> {
174
174
  const response = await axios.post(
175
175
  `${this.authServer}auth/email/verify`,
176
176
  {
177
177
  realm_name: this.realmName,
178
178
  email,
179
- code,
179
+ token,
180
180
  },
181
181
  );
182
182
  if (response.data.error || response.data.errors) {
@@ -186,12 +186,14 @@ export class AuthManager {
186
186
  return response.status === 200;
187
187
  }
188
188
 
189
- public async doPassReset(email: string, code: string, newPassword: string): Promise<boolean> {
189
+ public async doPassReset(email: string, token: string, newPassword: string): Promise<boolean> {
190
190
  const response = await axios.post(
191
191
  `${this.authServer}auth/email/do_pass_reset`,
192
192
  {
193
193
  realm_name: this.realmName,
194
194
  email,
195
+ token,
196
+ new_password: newPassword,
195
197
  },
196
198
  );
197
199
  if (response.data.error || response.data.errors) {
@@ -369,24 +371,24 @@ export class AuthManager {
369
371
  // @todo add caching for public key and algo
370
372
  const decodedToken = jwtDecode(bearerToken, {
371
373
  complete: true,
372
- })?.payload;
374
+ })?.payload as unknown as UserTokenPayload;
373
375
 
374
376
  if (!decodedToken) {
375
377
  throw new Error('Not a valid jwt token');
376
378
  }
377
379
 
378
380
  const userToken: UserTokenPayload = {
379
- id: decodedToken['id'],
380
- iss: decodedToken['iss'],
381
- sub: parseInt(decodedToken['sub'] as string),
382
- first_name: decodedToken['first_name'],
383
- last_name: decodedToken['last_name'],
384
- email: decodedToken['email'],
385
- aud: decodedToken['aud'],
386
- iat: decodedToken['iat'],
387
- exp: decodedToken['exp'],
388
- scopes: decodedToken['scopes'],
389
- realm: decodedToken['realm'],
381
+ id: decodedToken.id,
382
+ iss: decodedToken.iss,
383
+ sub: typeof decodedToken.sub === 'string' ? parseInt(decodedToken.sub) : decodedToken.sub,
384
+ first_name: decodedToken.first_name,
385
+ last_name: decodedToken.last_name,
386
+ email: decodedToken.email,
387
+ aud: decodedToken.aud,
388
+ iat: decodedToken.iat,
389
+ exp: decodedToken.exp,
390
+ scopes: decodedToken.scopes,
391
+ realm: decodedToken.realm,
390
392
  }
391
393
 
392
394
  const { data: publicKey } = await axios.get(
@@ -401,7 +403,7 @@ export class AuthManager {
401
403
  const { data: revokedIds } = await axios.get(
402
404
  `${authServer}public/revoked_ids`,
403
405
  );
404
- if(revokedIds.includes(decodedToken['id'])){
406
+ if(revokedIds.includes(decodedToken.id)){
405
407
  throw new Error('Token is revoked');
406
408
  }
407
409
  return userToken;
package/src/types.ts CHANGED
@@ -12,7 +12,7 @@ export enum AuthEventType {
12
12
  export interface UserTokenPayload {
13
13
  id: number;
14
14
  iss: string;
15
- sub: number;
15
+ sub: number | string;
16
16
  first_name: string;
17
17
  last_name: string;
18
18
  email: string;