@movalib/movalib-commons 1.1.53 → 1.1.54

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.
@@ -63,8 +63,8 @@ var request = function (options) {
63
63
  }
64
64
  break;
65
65
  case Enums_1.MovaAppType.GARAGE:
66
- if ((0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_GARAGE_TOKEN)) {
67
- headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_GARAGE_TOKEN));
66
+ if ((0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_PRO_TOKEN)) {
67
+ headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_PRO_TOKEN));
68
68
  }
69
69
  break;
70
70
  }
@@ -1,4 +1,4 @@
1
- export declare const COOKIE_GARAGE_TOKEN: string;
1
+ export declare const COOKIE_PRO_TOKEN: string;
2
2
  export declare const COOKIE_INDIVIDUAL_TOKEN: string;
3
3
  export declare const COOKIE_DEFAULT_EXPIRES: number;
4
4
  export declare const createCookie: (name: string, value: string) => void;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readCookie = exports.deleteCookie = exports.createCookie = exports.COOKIE_DEFAULT_EXPIRES = exports.COOKIE_INDIVIDUAL_TOKEN = exports.COOKIE_GARAGE_TOKEN = void 0;
6
+ exports.readCookie = exports.deleteCookie = exports.createCookie = exports.COOKIE_DEFAULT_EXPIRES = exports.COOKIE_INDIVIDUAL_TOKEN = exports.COOKIE_PRO_TOKEN = void 0;
7
7
  var js_cookie_1 = __importDefault(require("js-cookie"));
8
- exports.COOKIE_GARAGE_TOKEN = 'movalibGarageToken';
8
+ exports.COOKIE_PRO_TOKEN = 'movalibProToken';
9
9
  exports.COOKIE_INDIVIDUAL_TOKEN = 'movalibIndividualToken';
10
10
  exports.COOKIE_DEFAULT_EXPIRES = 7;
11
11
  var createCookie = function (name, value) {
@@ -60,7 +60,7 @@ var AuthenticationService = /** @class */ (function () {
60
60
  switch (appType) {
61
61
  case Enums_1.MovaAppType.GARAGE:
62
62
  url = "".concat(ApiHelper_1.API_BASE_URL, "/garage/login");
63
- tokenCookie = CookieUtils_1.COOKIE_GARAGE_TOKEN;
63
+ tokenCookie = CookieUtils_1.COOKIE_PRO_TOKEN;
64
64
  break;
65
65
  case Enums_1.MovaAppType.INDIVIDUAL:
66
66
  url = "".concat(ApiHelper_1.API_BASE_URL, "/login");
@@ -81,7 +81,7 @@ var AuthenticationService = /** @class */ (function () {
81
81
  if (!tokenResponse.success) return [3 /*break*/, 3];
82
82
  Logger_1.default.info(tokenResponse);
83
83
  (0, CookieUtils_1.createCookie)(tokenCookie, tokenResponse.data.accessToken);
84
- return [4 /*yield*/, UserService_1.default.getCurrentUser()];
84
+ return [4 /*yield*/, UserService_1.default.getCurrentUser(appType)];
85
85
  case 2:
86
86
  userResponse = _a.sent();
87
87
  if (!userResponse || !userResponse.success) {
@@ -1,4 +1,5 @@
1
1
  import { APIResponse } from "../helpers/ApiHelper";
2
+ import { MovaAppType } from "../helpers/Enums";
2
3
  import User from "../models/User";
3
4
  export default class UserService {
4
5
  static validateAccount(req: any): Promise<APIResponse<string>>;
@@ -7,5 +8,5 @@ export default class UserService {
7
8
  * @param password
8
9
  * @returns
9
10
  */
10
- static getCurrentUser(): Promise<APIResponse<User>>;
11
+ static getCurrentUser(appType: MovaAppType): Promise<APIResponse<User>>;
11
12
  }
@@ -58,7 +58,7 @@ var UserService = /** @class */ (function () {
58
58
  * @param password
59
59
  * @returns
60
60
  */
61
- UserService.getCurrentUser = function () {
61
+ UserService.getCurrentUser = function (appType) {
62
62
  return __awaiter(this, void 0, void 0, function () {
63
63
  var error_1;
64
64
  return __generator(this, function (_a) {
@@ -68,7 +68,7 @@ var UserService = /** @class */ (function () {
68
68
  return [4 /*yield*/, (0, ApiHelper_1.request)({
69
69
  url: "".concat(ApiHelper_1.API_BASE_URL, "/user/me"),
70
70
  method: Enums_1.APIMethod.GET,
71
- appType: Enums_1.MovaAppType.INDIVIDUAL
71
+ appType: appType
72
72
  })];
73
73
  case 1: return [2 /*return*/, _a.sent()];
74
74
  case 2:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.1.53",
3
+ "version": "1.1.54",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { APIMethod, MovaAppType } from "./Enums";
2
- import { COOKIE_GARAGE_TOKEN, COOKIE_INDIVIDUAL_TOKEN, readCookie } from "./CookieUtils";
2
+ import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, readCookie } from "./CookieUtils";
3
3
  import Logger from "./Logger";
4
4
  import { useHistory } from "react-router-dom";
5
5
 
@@ -84,8 +84,8 @@ export const request = (options:APIRequest): Promise<APIResponse<any>> => {
84
84
  break;
85
85
 
86
86
  case MovaAppType.GARAGE:
87
- if(readCookie(COOKIE_GARAGE_TOKEN)) {
88
- headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_GARAGE_TOKEN))
87
+ if(readCookie(COOKIE_PRO_TOKEN)) {
88
+ headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_PRO_TOKEN))
89
89
  }
90
90
  break;
91
91
  }
@@ -1,6 +1,6 @@
1
1
  import Cookies from "js-cookie";
2
2
 
3
- export const COOKIE_GARAGE_TOKEN: string = 'movalibGarageToken';
3
+ export const COOKIE_PRO_TOKEN: string = 'movalibProToken';
4
4
  export const COOKIE_INDIVIDUAL_TOKEN: string = 'movalibIndividualToken';
5
5
  export const COOKIE_DEFAULT_EXPIRES: number = 7;
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
2
- import { COOKIE_GARAGE_TOKEN, COOKIE_INDIVIDUAL_TOKEN, createCookie } from "../helpers/CookieUtils";
2
+ import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, createCookie } from "../helpers/CookieUtils";
3
3
  import { APIMethod, MovaAppType } from "../helpers/Enums";
4
4
  import Logger from "../helpers/Logger";
5
5
  import User from "../models/User";
@@ -19,7 +19,7 @@ export default class AuthenticationService {
19
19
  switch(appType){
20
20
  case MovaAppType.GARAGE:
21
21
  url = `${API_BASE_URL}/garage/login`;
22
- tokenCookie = COOKIE_GARAGE_TOKEN;
22
+ tokenCookie = COOKIE_PRO_TOKEN;
23
23
  break;
24
24
  case MovaAppType.INDIVIDUAL:
25
25
  url = `${API_BASE_URL}/login`;
@@ -44,7 +44,7 @@ export default class AuthenticationService {
44
44
  createCookie(tokenCookie, tokenResponse.data.accessToken);
45
45
 
46
46
  // Si le login est un succès, on renvoie les infos de l'utilisateur connecté
47
- let userResponse = await UserService.getCurrentUser();
47
+ let userResponse = await UserService.getCurrentUser(appType);
48
48
 
49
49
  if(!userResponse || !userResponse.success) {
50
50
  const errorMsg = 'Erreur au chargement de votre profil';
@@ -19,12 +19,12 @@ export default class UserService {
19
19
  * @param password
20
20
  * @returns
21
21
  */
22
- static async getCurrentUser(): Promise<APIResponse<User>> {
22
+ static async getCurrentUser(appType: MovaAppType): Promise<APIResponse<User>> {
23
23
  try {
24
24
  return await request({
25
25
  url: `${API_BASE_URL}/user/me`,
26
26
  method: APIMethod.GET,
27
- appType: MovaAppType.INDIVIDUAL
27
+ appType: appType
28
28
  });
29
29
  } catch (error) {
30
30
  Logger.error('Error occurred during getting user:', error);