zrok/ui/src/index.js

31 lines
704 B
JavaScript
Raw Normal View History

2022-08-01 21:54:20 +02:00
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
2022-08-02 20:24:01 +02:00
import * as gateway from "./api/gateway";
2022-09-19 21:37:49 +02:00
import App from "./App";
2022-08-01 21:54:20 +02:00
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
2022-09-19 21:37:49 +02:00
<App />
2022-08-02 20:24:01 +02:00
);
gateway.init({
url: '/api/v1',
getAuthorization
});
function getAuthorization(security) {
switch(security.id) {
case 'key': return getApiKey();
default: console.log('default');
}
}
function getApiKey() {
const localUser = JSON.parse(localStorage.getItem("user"))
if(localUser) {
return Promise.resolve({ apiKey: localUser.token });
} else {
throw new Error("token not available");
}
}