Skip to content

Commit 814ce15

Browse files
authored
Revert "feat: Use modal for authentication (#2443)" (#2451)
This reverts commit 627da6c.
1 parent 8760c60 commit 814ce15

File tree

3 files changed

+15
-80
lines changed

3 files changed

+15
-80
lines changed

src/Main.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,13 @@ const ConnectedDashboardPage = lazy(() =>
5252
import('./components/dashboard-page/Dashboard').then((module) => ({ default: module.ConnectedDashboardPage })),
5353
);
5454

55-
import { AuthForm } from './components/modal/components/AuthModal';
56-
5755
export function Main() {
5856
const { theme } = store.getState();
5957
return (
6058
<React.StrictMode>
6159
<ReactNotifications />
6260
<I18nextProvider i18n={i18n}>
6361
<NiceModal.Provider>
64-
<AuthForm id="auth-form" onAuth={() => null} />
6562
<Provider store={store}>
6663
<ThemeSwitcherProvider
6764
themeMap={{

src/components/modal/components/AuthModal.tsx

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/ws-client.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
stringifyWithPreservingUndefinedAsNull,
1010
} from './utils';
1111

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

@@ -114,27 +113,21 @@ class Api {
114113
}
115114
}
116115

117-
urlProvider = async (): Promise<string> => {
118-
const promise = new Promise<string>((resolve) => {
119-
const url = new URL(this.url)
120-
let token = new URLSearchParams(window.location.search).get("token")
121-
?? local.get<string>(TOKEN_LOCAL_STORAGE_ITEM_NAME);
122-
const authRequired = !!local.get(AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME);
123-
if (authRequired) {
124-
if (!token) {
125-
NiceModal.show('auth-form', { onAuth: (token: string) => {
126-
local.set(TOKEN_LOCAL_STORAGE_ITEM_NAME, token);
127-
url.searchParams.append("token", token);
128-
resolve(url.toString());
129-
}});
130-
return;
116+
urlProvider = async () => {
117+
const url = new URL(this.url)
118+
let token = new URLSearchParams(window.location.search).get("token")
119+
?? local.get<string>(TOKEN_LOCAL_STORAGE_ITEM_NAME);
120+
const authRequired = !!local.get(AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME);
121+
if (authRequired) {
122+
if (!token) {
123+
token = prompt("Enter your z2m admin token") as string;
124+
if (token) {
125+
local.set(TOKEN_LOCAL_STORAGE_ITEM_NAME, token);
131126
}
132-
url.searchParams.append("token", token);
133127
}
134-
resolve(url.toString());
135-
});
136-
137-
return promise;
128+
url.searchParams.append("token", token);
129+
}
130+
return url.toString();
138131
}
139132

140133
connect(): void {
@@ -284,7 +277,7 @@ class Api {
284277
if (e.code === UNAUTHORIZED_ERROR_CODE) {
285278
local.set(AUTH_FLAG_LOCAL_STORAGE_ITEM_NAME, true);
286279
local.remove(TOKEN_LOCAL_STORAGE_ITEM_NAME);
287-
showNotify('error', "Unauthorized", false);
280+
NotificationManager.error("Unauthorized");
288281
setTimeout(() => {
289282
window.location.reload();
290283
}, 1000);
@@ -303,7 +296,7 @@ class Api {
303296
this.processDeviceStateMessage(data);
304297
}
305298
} catch (e) {
306-
showNotify('error', e.message, false);
299+
NotificationManager.error(e.message);
307300
console.error(event.data);
308301
}
309302

0 commit comments

Comments
 (0)