Skip to content

Commit 4b2d5f6

Browse files
committed
fix session id
1 parent 4285943 commit 4b2d5f6

File tree

1 file changed

+10
-40
lines changed

1 file changed

+10
-40
lines changed

src/app/dfSlice.tsx

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -228,45 +228,17 @@ export const fetchAvailableModels = createAsyncThunk(
228228
}
229229
);
230230

231-
// Add this helper function to generate a UUID
232-
const generateSessionId = () => {
233-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
234-
const r = Math.random() * 16 | 0,
235-
v = c == 'x' ? r : (r & 0x3 | 0x8);
236-
return v.toString(16);
237-
});
238-
};
239-
240-
// Create or retrieve a session ID from local storage
241-
const getOrCreateSessionId = () => {
242-
let sessionId = localStorage.getItem('app_session_id');
243-
if (!sessionId) {
244-
sessionId = generateSessionId();
245-
localStorage.setItem('app_session_id', sessionId);
246-
}
247-
return sessionId;
248-
};
249-
250-
// Update your fetch function to include the session ID in the request
251231
export const fetchSessionId = createAsyncThunk(
252-
"dataFormulatorSlice/fetchSessionId",
253-
async () => {
254-
const sessionId = getOrCreateSessionId();
255-
256-
const response = await fetch(getUrls().SESSION_ID, {
257-
method: 'GET',
258-
headers: {
259-
'Content-Type': 'application/json',
260-
'X-Session-ID': sessionId // Pass session ID as a custom header
261-
}
262-
});
263-
264-
const data = await response.json();
265-
return {
266-
...data,
267-
session_id: sessionId // Ensure we return the session ID
268-
};
269-
}
232+
"dataFormulatorSlice/fetchSessionId",
233+
async () => {
234+
const response = await fetch(getUrls().SESSION_ID, {
235+
method: 'GET',
236+
headers: {
237+
'Content-Type': 'application/json',
238+
}
239+
});
240+
return response.json();
241+
}
270242
);
271243

272244
export const dataFormulatorSlice = createSlice({
@@ -731,8 +703,6 @@ export const dataFormulatorSlice = createSlice({
731703
console.log(action.payload);
732704
})
733705
.addCase(fetchSessionId.fulfilled, (state, action) => {
734-
console.log(">>> fetchSessionId <<<")
735-
console.log(action.payload)
736706
state.sessionId = action.payload.session_id;
737707
})
738708
},

0 commit comments

Comments
 (0)