Skip to content

Commit 4c5b07e

Browse files
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 * 🐛 Add = to the param key to avoid key conflicts lib/auth.ts --------- Co-authored-by: Lancelot Owczarczak <[email protected]>
1 parent fc3c617 commit 4c5b07e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/auth.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,26 @@ export async function getSession(
6161
refreshToken = storedRefreshToken;
6262
} else if (refreshToken) {
6363
setSessionStorage(refreshToken, projectId);
64-
window.history.replaceState({}, window.document.title, window.location.pathname);
64+
65+
// Removes access_token and refresh_token from the URL
66+
// Required otherwise other useful link params are lost
67+
const url = new URL(window.location.href);
68+
if (url.hash.includes("access_token") || url.hash.includes("refresh_token")) {
69+
const newHash = url.hash
70+
.substring(1)
71+
.split("&")
72+
.filter(
73+
(param) =>
74+
!param.startsWith("access_token=") && !param.startsWith("refresh_token="),
75+
)
76+
.join("&");
77+
78+
window.history.replaceState(
79+
{},
80+
window.document.title,
81+
`${url.pathname}${url.search}${newHash ? `#${newHash}` : ""}`,
82+
);
83+
}
6584
}
6685

6786
if (!refreshToken) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polyfire-js",
3-
"version": "0.2.57",
3+
"version": "0.2.58",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"author": "Lancelot Owczarczak <[email protected]>",

0 commit comments

Comments
 (0)