@viridial/shared 1.0.5 → 1.0.7

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 +1 @@
1
- {"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../api/auth.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAGlJ;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;OAEG;uBACsB,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAQ9D;;OAEG;iBACgB,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAK1D;;OAEG;cACa,OAAO,CAAC,IAAI,CAAC;IAQ7B;;OAEG;yBACwB,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE;;OAEG;wBACuB,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D;;OAEG;oBACmB,OAAO,CAAC,aAAa,CAAC;IAQ5C;;OAEG;uBACgB,OAAO;CAG3B,CAAA"}
1
+ {"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../api/auth.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAGlJ;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;OAEG;uBACsB,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAkB9D;;OAEG;iBACgB,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAK1D;;OAEG;cACa,OAAO,CAAC,IAAI,CAAC;IAQ7B;;OAEG;yBACwB,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhE;;OAEG;wBACuB,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9D;;OAEG;oBACmB,OAAO,CAAC,aAAa,CAAC;IAQ5C;;OAEG;uBACgB,OAAO;CAG3B,CAAA"}
@@ -10,10 +10,20 @@ export const authService = {
10
10
  */
11
11
  async login(credentials) {
12
12
  const response = await httpClient.post(API_ENDPOINTS.AUTH.LOGIN, credentials);
13
- if (response.data?.token) {
14
- tokenUtils.setToken(response.data.token);
13
+ // L'API retourne accessToken ou token
14
+ const token = response.data?.accessToken || response.data?.token;
15
+ if (token) {
16
+ tokenUtils.setToken(token);
15
17
  }
16
- return response.data;
18
+ // Stocker aussi le refreshToken si présent
19
+ if (response.data?.refreshToken) {
20
+ tokenUtils.setRefreshToken(response.data.refreshToken);
21
+ }
22
+ // Normaliser la réponse pour avoir toujours 'token'
23
+ return {
24
+ ...response.data,
25
+ token: token || response.data?.token
26
+ };
17
27
  },
18
28
  /**
19
29
  * Inscription
@@ -18,7 +18,7 @@ export declare const API_ENDPOINTS: {
18
18
  readonly USERS: {
19
19
  readonly BASE: "/api/identity/users";
20
20
  readonly BY_ID: (id: number) => string;
21
- readonly PROFILE: "/api/identity/users/profile";
21
+ readonly PROFILE: "/api/identity/users/me";
22
22
  readonly STATS: "/api/identity/users/stats";
23
23
  readonly SEARCH: "/api/identity/users/search";
24
24
  readonly ACTIVITY: (id: number) => string;
@@ -21,7 +21,7 @@ export const API_ENDPOINTS = {
21
21
  USERS: {
22
22
  BASE: '/api/identity/users',
23
23
  BY_ID: (id) => `/api/identity/users/${id}`,
24
- PROFILE: '/api/identity/users/profile',
24
+ PROFILE: '/api/identity/users/me', // Endpoint backend: /me
25
25
  STATS: '/api/identity/users/stats',
26
26
  SEARCH: '/api/identity/users/search',
27
27
  ACTIVITY: (id) => `/api/identity/users/${id}/activity`
@@ -23,7 +23,7 @@ export declare const useAuthStore: import("pinia").StoreDefinition<"auth", Pick<
23
23
  userName: import("vue").ComputedRef<string>;
24
24
  login: (credentials: LoginRequest) => Promise<void>;
25
25
  logout: () => Promise<void>;
26
- checkAuth: () => void;
26
+ checkAuth: () => Promise<void>;
27
27
  setUser: (userData: UserInfo) => void;
28
28
  }, "user" | "isAuthenticated" | "loading">, Pick<{
29
29
  user: import("vue").Ref<{
@@ -46,7 +46,7 @@ export declare const useAuthStore: import("pinia").StoreDefinition<"auth", Pick<
46
46
  userName: import("vue").ComputedRef<string>;
47
47
  login: (credentials: LoginRequest) => Promise<void>;
48
48
  logout: () => Promise<void>;
49
- checkAuth: () => void;
49
+ checkAuth: () => Promise<void>;
50
50
  setUser: (userData: UserInfo) => void;
51
51
  }, "isAdmin" | "isAgent" | "userName">, Pick<{
52
52
  user: import("vue").Ref<{
@@ -69,7 +69,7 @@ export declare const useAuthStore: import("pinia").StoreDefinition<"auth", Pick<
69
69
  userName: import("vue").ComputedRef<string>;
70
70
  login: (credentials: LoginRequest) => Promise<void>;
71
71
  logout: () => Promise<void>;
72
- checkAuth: () => void;
72
+ checkAuth: () => Promise<void>;
73
73
  setUser: (userData: UserInfo) => void;
74
74
  }, "login" | "logout" | "checkAuth" | "setUser">>;
75
75
  //# sourceMappingURL=auth.store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.store.d.ts","sourceRoot":"","sources":["../../stores/auth.store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAIjE;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;yBAmBW,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC;kBAarC,OAAO,CAAC,IAAI,CAAC;qBAShB,IAAI;wBAOC,QAAQ,KAAG,IAAI;;;;;;;;;;;;;;;;;;;;yBA7BR,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC;kBAarC,OAAO,CAAC,IAAI,CAAC;qBAShB,IAAI;wBAOC,QAAQ,KAAG,IAAI;;;;;;;;;;;;;;;;;;;;yBA7BR,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC;kBAarC,OAAO,CAAC,IAAI,CAAC;qBAShB,IAAI;wBAOC,QAAQ,KAAG,IAAI;iDAoB1C,CAAA"}
1
+ {"version":3,"file":"auth.store.d.ts","sourceRoot":"","sources":["../../stores/auth.store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAKjE;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;yBAmBW,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC;kBA0CrC,OAAO,CAAC,IAAI,CAAC;qBASV,OAAO,CAAC,IAAI,CAAC;wBAkCd,QAAQ,KAAG,IAAI;;;;;;;;;;;;;;;;;;;;yBArFR,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC;kBA0CrC,OAAO,CAAC,IAAI,CAAC;qBASV,OAAO,CAAC,IAAI,CAAC;wBAkCd,QAAQ,KAAG,IAAI;;;;;;;;;;;;;;;;;;;;yBArFR,YAAY,KAAG,OAAO,CAAC,IAAI,CAAC;kBA0CrC,OAAO,CAAC,IAAI,CAAC;qBASV,OAAO,CAAC,IAAI,CAAC;wBAkCd,QAAQ,KAAG,IAAI;iDAoB1C,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { defineStore } from 'pinia';
2
2
  import { ref, computed } from 'vue';
3
3
  import { authService } from '../api/auth.service';
4
+ import { userService } from '../api/user.service';
4
5
  import { tokenUtils } from '../utils/token.utils';
5
6
  /**
6
7
  * Store d'authentification
@@ -23,9 +24,36 @@ export const useAuthStore = defineStore('auth', () => {
23
24
  async function login(credentials) {
24
25
  loading.value = true;
25
26
  try {
27
+ // 1. Se connecter et obtenir le token
26
28
  const response = await authService.login(credentials);
27
- user.value = response.user;
29
+ // 2. Le token est déjà stocké par authService.login()
30
+ // 3. Marquer comme authentifié immédiatement
28
31
  isAuthenticated.value = true;
32
+ // 4. Récupérer les infos utilisateur depuis le profil
33
+ try {
34
+ const profile = await userService.getProfile();
35
+ // Mapper UserProfile vers UserInfo
36
+ // Le backend retourne roleNames (Set<String>) dans UserDTO
37
+ const roleNames = profile.roleNames || profile.roles || [];
38
+ const rolesArray = Array.isArray(roleNames)
39
+ ? roleNames.map((r) => String(r))
40
+ : Array.from(roleNames || []).map((r) => String(r));
41
+ user.value = {
42
+ id: profile.id,
43
+ email: profile.email,
44
+ name: profile.firstName && profile.lastName
45
+ ? `${profile.firstName} ${profile.lastName}`
46
+ : profile.name || profile.email,
47
+ roles: rolesArray,
48
+ organizationId: profile.organizationId
49
+ };
50
+ }
51
+ catch (profileError) {
52
+ // Si l'API profile échoue, on garde quand même l'authentification
53
+ // L'utilisateur sera chargé plus tard par checkAuth()
54
+ console.warn('Failed to fetch user profile after login:', profileError);
55
+ // On reste authentifié même sans user pour l'instant
56
+ }
29
57
  }
30
58
  catch (error) {
31
59
  throw error;
@@ -43,10 +71,38 @@ export const useAuthStore = defineStore('auth', () => {
43
71
  isAuthenticated.value = false;
44
72
  }
45
73
  }
46
- function checkAuth() {
74
+ async function checkAuth() {
47
75
  if (tokenUtils.hasToken()) {
48
76
  isAuthenticated.value = true;
49
- // TODO: Récupérer les infos utilisateur depuis le token ou API
77
+ // Récupérer les infos utilisateur depuis l'API si pas déjà chargé
78
+ if (!user.value) {
79
+ try {
80
+ const profile = await userService.getProfile();
81
+ // Le backend retourne roleNames (Set<String>) dans UserDTO
82
+ const roleNames = profile.roleNames || profile.roles || [];
83
+ const rolesArray = Array.isArray(roleNames)
84
+ ? roleNames.map((r) => String(r))
85
+ : Array.from(roleNames || []).map((r) => String(r));
86
+ user.value = {
87
+ id: profile.id,
88
+ email: profile.email,
89
+ name: profile.firstName && profile.lastName
90
+ ? `${profile.firstName} ${profile.lastName}`
91
+ : profile.name || profile.email,
92
+ roles: rolesArray,
93
+ organizationId: profile.organizationId
94
+ };
95
+ }
96
+ catch (error) {
97
+ console.error('Failed to fetch user profile in checkAuth:', error);
98
+ // Si l'API échoue, on garde l'authentification mais sans user
99
+ // Le token est valide, donc on reste authentifié
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ isAuthenticated.value = false;
105
+ user.value = null;
50
106
  }
51
107
  }
52
108
  function setUser(userData) {
@@ -6,9 +6,12 @@ export interface LoginRequest {
6
6
  password: string;
7
7
  }
8
8
  export interface LoginResponse {
9
- token: string;
9
+ accessToken?: string;
10
+ token?: string;
10
11
  refreshToken?: string;
11
- user: UserInfo;
12
+ tokenType?: string;
13
+ expiresIn?: number;
14
+ user?: UserInfo;
12
15
  }
13
16
  export interface SignupRequest {
14
17
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../../types/auth.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,QAAQ,CAAA;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
1
+ {"version":3,"file":"auth.types.d.ts","sourceRoot":"","sources":["../../types/auth.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viridial/shared",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "Shared modules for Real Estate frontend applications - Vue 3, TypeScript, Pinia, Axios",
6
6
  "main": "./dist/index.js",