Skip to content

Commit

Permalink
fix: cleaning the URL properly (#136)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
victorforissier and lowczarc authored Mar 8, 2024
1 parent fc3c617 commit 4c5b07e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down

0 comments on commit 4c5b07e

Please sign in to comment.