From 4c5b07e450f97a129f7290ddcdbe29c3dd03ed84 Mon Sep 17 00:00:00 2001 From: Victor Forissier <34337148+victorforissier@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:10:55 +0900 Subject: [PATCH] fix: cleaning the URL properly (#136) * fix: cleaning the URL properly * style: shortening using filters * build: updating version * style: no anonymous function * style: no anonymous function * :bug: Add = to the param key to avoid key conflicts lib/auth.ts --------- Co-authored-by: Lancelot Owczarczak --- lib/auth.ts | 21 ++++++++++++++++++++- package.json | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) 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 ",