From 6583861dbe7c28074ae1c05ca06378db8b759901 Mon Sep 17 00:00:00 2001 From: Kris Szlapa Date: Wed, 13 Nov 2024 17:51:15 +0000 Subject: [PATCH] Clear all cookies with CognitoIdentityServiceProvider prefix before making the request --- packages/auth_demo/src/App.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/auth_demo/src/App.tsx b/packages/auth_demo/src/App.tsx index 7eca184..26c002d 100644 --- a/packages/auth_demo/src/App.tsx +++ b/packages/auth_demo/src/App.tsx @@ -65,12 +65,25 @@ function App() { } } + const clearCognitoCookies = () => { + const cookies = document.cookie.split("; ") + cookies.forEach(cookie => { + if (cookie.startsWith("CognitoIdentityServiceProvider")) { + // Remove the cookie by setting its expiration date to the past + document.cookie = `${cookie.split("=")[0]}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;` + } + }) + } + const fetchPrescriptionData = async () => { if (!prescriptionId) { setError('Please enter a Prescription ID.') return } + // Clear all cookies with 'CognitoIdentityServiceProvider' prefix before making the request + clearCognitoCookies() + setLoading(true) setPrescriptionData(null) setError(null)