Preserve url params in redirect uri (#8495)

This commit is contained in:
Paulus Schoutsen 2021-03-01 03:54:39 -08:00 committed by GitHub
parent 22c8af0cc5
commit f7a3d2705c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -48,10 +48,19 @@ const authProm = isExternal
const connProm = async (auth) => {
try {
const conn = await createConnection({ auth });
// Clear url if we have been able to establish a connection
// Clear auth data from url if we have been able to establish a connection
if (location.search.includes("auth_callback=1")) {
history.replaceState(null, "", location.pathname);
const searchParams = new URLSearchParams(location.search);
// https://github.com/home-assistant/home-assistant-js-websocket/blob/master/lib/auth.ts
// Remove all data from QueryCallbackData type
searchParams.delete("auth_callback");
searchParams.delete("code");
searchParams.delete("state");
history.replaceState(
null,
"",
`${location.pathname}?${searchParams.toString()}`
);
}
return { auth, conn };