@viridial/shared 1.0.4 → 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.
- package/dist/api/auth.service.d.ts.map +1 -1
- package/dist/api/auth.service.js +13 -3
- package/dist/api/http.client.d.ts.map +1 -1
- package/dist/api/http.client.js +4 -7
- package/dist/constants/api.constants.d.ts +12 -2
- package/dist/constants/api.constants.d.ts.map +1 -1
- package/dist/constants/api.constants.js +9 -12
- package/dist/stores/auth.store.d.ts +3 -3
- package/dist/stores/auth.store.d.ts.map +1 -1
- package/dist/stores/auth.store.js +59 -3
- package/dist/types/auth.types.d.ts +5 -2
- package/dist/types/auth.types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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;
|
|
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"}
|
package/dist/api/auth.service.js
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.client.d.ts","sourceRoot":"","sources":["../../api/http.client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAsB,KAAK,kBAAkB,EAAsB,MAAM,OAAO,CAAA;AAC9F,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"http.client.d.ts","sourceRoot":"","sources":["../../api/http.client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAsB,KAAK,kBAAkB,EAAsB,MAAM,OAAO,CAAA;AAC9F,OAAO,KAAK,EAAE,WAAW,EAAY,MAAM,oBAAoB,CAAA;AAgB/D;;GAEG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAe;gBAEjB,OAAO,CAAC,EAAE,MAAM;IAc5B,OAAO,CAAC,iBAAiB;IAkCzB,OAAO,CAAC,WAAW;IAcb,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IASzE,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAStF,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IASrF,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IASvF,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAQnF;AAED,eAAO,MAAM,UAAU,YAAmB,CAAA"}
|
package/dist/api/http.client.js
CHANGED
|
@@ -4,15 +4,12 @@ import { tokenUtils } from '../utils/token.utils';
|
|
|
4
4
|
* Get API base URL from environment or use default
|
|
5
5
|
* Note: In the shared package, we use empty string as default
|
|
6
6
|
* The endpoints already include '/api' prefix for Vite proxy
|
|
7
|
+
* The proxy in vite.config.ts redirects /api to VITE_API_BASE_URL
|
|
7
8
|
*/
|
|
8
9
|
const getApiBaseUrl = () => {
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// If baseURL already includes /api, return as is, otherwise add it
|
|
13
|
-
return baseUrl.endsWith('/api') ? baseUrl : `${baseUrl}/api`;
|
|
14
|
-
}
|
|
15
|
-
// Default: empty string (endpoints already include /api prefix)
|
|
10
|
+
// Always use empty string - endpoints already include /api prefix
|
|
11
|
+
// The Vite proxy will handle redirecting /api to the gateway
|
|
12
|
+
// Example: /api/identity/auth/login -> proxy -> http://localhost:8080/api/identity/auth/login
|
|
16
13
|
return '';
|
|
17
14
|
};
|
|
18
15
|
/**
|
|
@@ -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/
|
|
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;
|
|
@@ -28,5 +28,15 @@ export declare const API_ENDPOINTS: {
|
|
|
28
28
|
readonly BY_ID: (id: number) => string;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Get API base URL from environment
|
|
33
|
+
* Note: This constant is not used by httpClient (which uses empty string)
|
|
34
|
+
* It's kept for backward compatibility and documentation purposes
|
|
35
|
+
* The actual routing works as follows:
|
|
36
|
+
* - Frontend requests: /api/identity/auth/login
|
|
37
|
+
* - Vite proxy: redirects /api to VITE_API_BASE_URL (http://localhost:8080)
|
|
38
|
+
* - Final URL: http://localhost:8080/api/identity/auth/login
|
|
39
|
+
* - Gateway routes: /api/identity/** to identity-service:8081
|
|
40
|
+
*/
|
|
41
|
+
export declare const API_BASE_URL = "/api";
|
|
32
42
|
//# sourceMappingURL=api.constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.constants.d.ts","sourceRoot":"","sources":["../../constants/api.constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;6BAcV,MAAM;;;;6BAKN,MAAM;;;;gCAIH,MAAM;;;;6BAKT,MAAM;;CAEZ,CAAA;
|
|
1
|
+
{"version":3,"file":"api.constants.d.ts","sourceRoot":"","sources":["../../constants/api.constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;6BAcV,MAAM;;;;6BAKN,MAAM;;;;gCAIH,MAAM;;;;6BAKT,MAAM;;CAEZ,CAAA;AAEV;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,SAAS,CAAA"}
|
|
@@ -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/
|
|
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`
|
|
@@ -34,15 +34,12 @@ export const API_ENDPOINTS = {
|
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Get API base URL from environment
|
|
37
|
-
* Note:
|
|
38
|
-
*
|
|
37
|
+
* Note: This constant is not used by httpClient (which uses empty string)
|
|
38
|
+
* It's kept for backward compatibility and documentation purposes
|
|
39
|
+
* The actual routing works as follows:
|
|
40
|
+
* - Frontend requests: /api/identity/auth/login
|
|
41
|
+
* - Vite proxy: redirects /api to VITE_API_BASE_URL (http://localhost:8080)
|
|
42
|
+
* - Final URL: http://localhost:8080/api/identity/auth/login
|
|
43
|
+
* - Gateway routes: /api/identity/** to identity-service:8081
|
|
39
44
|
*/
|
|
40
|
-
const
|
|
41
|
-
// Try to get from window (if set by Vite at runtime)
|
|
42
|
-
if (typeof window !== 'undefined' && window.__API_BASE_URL__) {
|
|
43
|
-
return window.__API_BASE_URL__;
|
|
44
|
-
}
|
|
45
|
-
// Default: use proxy path (Vite will proxy /api to the configured backend)
|
|
46
|
-
return '/api';
|
|
47
|
-
};
|
|
48
|
-
export const API_BASE_URL = getApiBaseUrl();
|
|
45
|
+
export const API_BASE_URL = '/api';
|
|
@@ -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;
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
9
|
+
accessToken?: string;
|
|
10
|
+
token?: string;
|
|
10
11
|
refreshToken?: string;
|
|
11
|
-
|
|
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;
|
|
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"}
|