Handle auth + cors
This commit is contained in:
parent
43f861fcc0
commit
12487011d2
@ -3,7 +3,7 @@ import { BROADCASTER, fetchData } from './utils/apis';
|
|||||||
|
|
||||||
export default function Admin() {
|
export default function Admin() {
|
||||||
const [broadcasterStatus, setBroadcasterStatus] = useState({});
|
const [broadcasterStatus, setBroadcasterStatus] = useState({});
|
||||||
let getStatusIntervalId = null;
|
const getStatusIntervalId = null;
|
||||||
|
|
||||||
|
|
||||||
const getBroadcastStatus = async () => {
|
const getBroadcastStatus = async () => {
|
||||||
@ -12,7 +12,8 @@ export default function Admin() {
|
|||||||
const active = !!result.broadcaster;
|
const active = !!result.broadcaster;
|
||||||
|
|
||||||
setBroadcasterStatus({ ...result, active });
|
setBroadcasterStatus({ ...result, active });
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
|
|
||||||
setBroadcasterStatus({ ...broadcasterStatus, message: error.message });
|
setBroadcasterStatus({ ...broadcasterStatus, message: error.message });
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,7 +23,6 @@ export default function Admin() {
|
|||||||
useEffect(() => { getBroadcastStatus(); }, []);
|
useEffect(() => { getBroadcastStatus(); }, []);
|
||||||
|
|
||||||
|
|
||||||
console.log("============",broadcasterStatus)
|
|
||||||
// getStatusIntervalId = setInterval(getBroadcastStatus, 15000);
|
// getStatusIntervalId = setInterval(getBroadcastStatus, 15000);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -31,29 +31,31 @@ export const HARDWARE_STATS = `${API_LOCATION}hardwarestats`;
|
|||||||
// export const STREAM_STATUS = '/api/status';
|
// export const STREAM_STATUS = '/api/status';
|
||||||
|
|
||||||
export async function fetchData(url) {
|
export async function fetchData(url) {
|
||||||
const headers = new Headers();
|
|
||||||
const encoded = btoa(`${ADMIN_USERNAME}:${ADMIN_STREAMKEY}`);
|
const encoded = btoa(`${ADMIN_USERNAME}:${ADMIN_STREAMKEY}`);
|
||||||
// headers.set('Authorization', `Basic ${encoded}`);
|
|
||||||
console.log({encoded}, `${ADMIN_USERNAME}:${ADMIN_STREAMKEY}`)
|
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Basic ${encoded}`,
|
'Authorization': `Basic ${encoded}`,
|
||||||
'Credentials': 'include',
|
|
||||||
},
|
},
|
||||||
mode: 'no-cors',
|
mode: 'cors',
|
||||||
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
// waits until the request completes...
|
// waits until the request completes...
|
||||||
// console.log(response);
|
// console.log(response);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
console.log(response)
|
||||||
const message = `An error has occured: ${response.status}`;
|
const message = `An error has occured: ${response.status}`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
console.log(json)
|
||||||
return json;
|
return json;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch error cases
|
// fetch error cases
|
||||||
|
Loading…
x
Reference in New Issue
Block a user