Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ const ConnectedDashboardPage = lazy(() =>
import('./components/dashboard-page/Dashboard').then((module) => ({ default: module.ConnectedDashboardPage })),
);

import { AuthForm } from './components/modal/components/AuthModal';

export function Main() {
const { theme } = store.getState();
return (
<React.StrictMode>
<ReactNotifications />
<I18nextProvider i18n={i18n}>
<NiceModal.Provider>
<AuthForm id="auth-form" onAuth={() => null} />
<Provider store={store}>
<ThemeSwitcherProvider
themeMap={{
Expand Down
55 changes: 0 additions & 55 deletions src/components/modal/components/AuthModal.tsx

This file was deleted.

37 changes: 15 additions & 22 deletions src/ws-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
stringifyWithPreservingUndefinedAsNull,
} from './utils';

import NiceModal from '@ebay/nice-modal-react';
import { Store } from 'react-notifications-component';
import keyBy from 'lodash/keyBy';

Expand Down Expand Up @@ -114,27 +113,21 @@ class Api {
}
}

urlProvider = async (): Promise<string> => {
const promise = new Promise<string>((resolve) => {
const url = new URL(this.url)
let token = new URLSearchParams(window.location.search).get("token")
?? local.get<string>(TOKEN_LOCAL_STORAGE_ITEM_NAME);
const authRequired = !!local.get(AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME);
if (authRequired) {
if (!token) {
NiceModal.show('auth-form', { onAuth: (token: string) => {
local.set(TOKEN_LOCAL_STORAGE_ITEM_NAME, token);
url.searchParams.append("token", token);
resolve(url.toString());
}});
return;
urlProvider = async () => {
const url = new URL(this.url)
let token = new URLSearchParams(window.location.search).get("token")
?? local.get<string>(TOKEN_LOCAL_STORAGE_ITEM_NAME);
const authRequired = !!local.get(AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME);
if (authRequired) {
if (!token) {
token = prompt("Enter your z2m admin token") as string;
if (token) {
local.set(TOKEN_LOCAL_STORAGE_ITEM_NAME, token);
}
url.searchParams.append("token", token);
}
resolve(url.toString());
});

return promise;
url.searchParams.append("token", token);
}
return url.toString();
}

connect(): void {
Expand Down Expand Up @@ -284,7 +277,7 @@ class Api {
if (e.code === UNAUTHORIZED_ERROR_CODE) {
local.set(AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME, true);
local.remove(TOKEN_LOCAL_STORAGE_ITEM_NAME);
showNotify('error', "Unauthorized", false);
NotificationManager.error("Unauthorized");
setTimeout(() => {
window.location.reload();
}, 1000);
Expand All @@ -303,7 +296,7 @@ class Api {
this.processDeviceStateMessage(data);
}
} catch (e) {
showNotify('error', e.message, false);
NotificationManager.error(e.message);
console.error(event.data);
}

Expand Down