diff --git a/lib/auth.ts b/lib/auth.ts index 1aa7735..57e9ebd 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -61,7 +61,26 @@ export async function getSession( refreshToken = storedRefreshToken; } else if (refreshToken) { setSessionStorage(refreshToken, projectId); - window.history.replaceState({}, window.document.title, window.location.pathname); + + // Removes access_token and refresh_token from the URL + // Required otherwise other useful link params are lost + const url = new URL(window.location.href); + if (url.hash.includes("access_token") || url.hash.includes("refresh_token")) { + const newHash = url.hash + .substring(1) + .split("&") + .filter( + (param) => + !param.startsWith("access_token=") && !param.startsWith("refresh_token="), + ) + .join("&"); + + window.history.replaceState( + {}, + window.document.title, + `${url.pathname}${url.search}${newHash ? `#${newHash}` : ""}`, + ); + } } if (!refreshToken) { diff --git a/package.json b/package.json index fa2a308..937f72f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polyfire-js", - "version": "0.2.57", + "version": "0.2.58", "main": "index.js", "types": "index.d.ts", "author": "Lancelot Owczarczak ",