@caseparts-org/casecore 0.0.7 → 0.0.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.
|
@@ -23,7 +23,7 @@ export type AuthContextType = {
|
|
|
23
23
|
fetch: (_url: string, _options?: RequestInit) => Promise<Response | null>;
|
|
24
24
|
hasRight: (_right: string) => boolean;
|
|
25
25
|
token: string | null;
|
|
26
|
-
sessionId: string;
|
|
26
|
+
sessionId: string | null;
|
|
27
27
|
};
|
|
28
28
|
export type Credentials = {
|
|
29
29
|
email: string;
|
|
@@ -89,7 +89,8 @@ export default function AuthProvider({ children, urls, apiKey, sessionClientId }
|
|
|
89
89
|
opts.headers = { ...(opts.headers || {}) };
|
|
90
90
|
if (token)
|
|
91
91
|
opts.headers.Authorization = "Bearer " + token;
|
|
92
|
-
|
|
92
|
+
if (sessionId)
|
|
93
|
+
opts.headers['X-Session-ID'] = sessionId;
|
|
93
94
|
opts.credentials = 'include';
|
|
94
95
|
return fancyFetch(url, opts)
|
|
95
96
|
.catch(e => {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Gets or creates a session ID stored in sessionStorage under a CPC-prefixed key.
|
|
3
3
|
*
|
|
4
4
|
* @param {string} clientId - The identifier to inject into the session key (e.g., 'CatBaker2').
|
|
5
|
-
* @returns {string} The session ID.
|
|
5
|
+
* @returns {string | null} The session ID.
|
|
6
6
|
*/
|
|
7
|
-
export declare const getSessionId: (clientId: string) => string;
|
|
7
|
+
export declare const getSessionId: (clientId: string) => string | null;
|
|
@@ -3,10 +3,14 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
3
3
|
* Gets or creates a session ID stored in sessionStorage under a CPC-prefixed key.
|
|
4
4
|
*
|
|
5
5
|
* @param {string} clientId - The identifier to inject into the session key (e.g., 'CatBaker2').
|
|
6
|
-
* @returns {string} The session ID.
|
|
6
|
+
* @returns {string | null} The session ID.
|
|
7
7
|
*/
|
|
8
8
|
export const getSessionId = (clientId) => {
|
|
9
9
|
const SESSION_ID_KEY = `CPC.${clientId}.SessionId`;
|
|
10
|
+
// Check if sessionStorage is available (window is defined and sessionStorage exists)
|
|
11
|
+
if (typeof window === "undefined" || !window.sessionStorage) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
10
14
|
// Check if we already have a session ID
|
|
11
15
|
let sessionId = sessionStorage.getItem(SESSION_ID_KEY);
|
|
12
16
|
// If not, generate a new one and store it
|