zrok/ui/src/index.js
2022-12-21 10:55:10 -05:00

31 lines
704 B
JavaScript

import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import * as gateway from "./api/gateway";
import App from "./App";
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<App />
);
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");
}
}