diff --git a/src/Main.tsx b/src/Main.tsx index f3ddb7e..b10222e 100644 --- a/src/Main.tsx +++ b/src/Main.tsx @@ -1,6 +1,7 @@ import { osmAuth } from "osm-auth"; import React, { Suspense, useEffect, useMemo, useState } from "react"; import { AppContext } from "~/appContext"; +import { fixOsmAuthLocalStorageTokens } from "~/auth"; import CustomModal from "~/components/modal"; import { AuthState } from "~/model/auth"; import { Country } from "~/model/country"; @@ -34,6 +35,9 @@ function Main() { const { VITE_OSM_API_URL, VITE_OSM_AUTH_URL, VITE_OSM_OAUTH2_CLIENT_ID } = import.meta.env; + useEffect(() => { + fixOsmAuthLocalStorageTokens(); + }, []); const redirectPath = window.location.origin + window.location.pathname; const [auth] = useState( new osmAuth({ diff --git a/src/auth.ts b/src/auth.ts new file mode 100644 index 0000000..eb65e36 --- /dev/null +++ b/src/auth.ts @@ -0,0 +1,11 @@ +export function fixOsmAuthLocalStorageTokens() { + for (const key in localStorage) { + if (key.includes("oauth")) { + const oldValue = localStorage.getItem(key); + if (oldValue?.includes('"')) { + const newValue = oldValue.replace(/"/g, ""); + localStorage.setItem(key, newValue); + } + } + } +}