Skip to content

Commit

Permalink
fix: extract loginToken using URLSearchParams (#275)
Browse files Browse the repository at this point in the history
It's more robust than a regex and also works with extras queries.

Signed-off-by: Hugo Renard <[email protected]>
  • Loading branch information
hrenard authored Jan 14, 2025
1 parent 1ca029f commit 5ed5a88
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,31 @@ const LoginPage = () => {
const translate = useTranslate();
const base_url = allowSingleBaseUrl ? restrictBaseUrl : localStorage.getItem("base_url");
const [ssoBaseUrl, setSSOBaseUrl] = useState("");
const loginToken = /\?loginToken=([a-zA-Z0-9_-]+)/.exec(window.location.href);
const loginToken = new URLSearchParams(window.location.search).get("loginToken")
const [loginMethod, setLoginMethod] = useState<LoginMethod>("credentials");

useEffect(() => {
if (!loginToken) {
return;
}

const ssoToken = loginToken[1];
console.log("SSO token is", ssoToken);
console.log("SSO token is", loginToken);
// Prevent further requests
window.history.replaceState({}, "", window.location.href.replace(loginToken[0], "#").split("#")[0]);
const previousUrl = new URL(window.location.toString())
previousUrl.searchParams.delete("loginToken")
previousUrl.hash = ""
window.history.replaceState({}, "", previousUrl.toString());
const baseUrl = localStorage.getItem("sso_base_url");
localStorage.removeItem("sso_base_url");
if (baseUrl) {
const auth = {
base_url: baseUrl,
username: null,
password: null,
loginToken: ssoToken,
loginToken,
};
console.log("Base URL is:", baseUrl);
console.log("SSO Token is:", ssoToken);
console.log("SSO Token is:", loginToken);
console.log("Let's try token login...");
login(auth).catch(error => {
alert(
Expand Down

0 comments on commit 5ed5a88

Please sign in to comment.