@wener/console
Version:
Base console UI toolkit
26 lines (25 loc) • 853 B
JavaScript
import React, { useEffect, useState } from "react";
import { AuthStatus, getAuthStore } from "./AuthStore.js";
export const AuthBlock = ({ children, fallback }) => {
let store = getAuthStore();
const [authed, setAuthed] = useState(() => {
return store.getState().status === AuthStatus.Authenticated;
});
useEffect(() => {
// if (authed) return;
let unsub = store.subscribe((s) => {
if (s.status === AuthStatus.Authenticated) {
setAuthed(true);
}
else if (s.status === AuthStatus.Unauthenticated) {
setAuthed(false);
}
});
return unsub;
}, []);
if (!authed) {
return fallback;
}
return /*#__PURE__*/ React.createElement(React.Fragment, null, children);
};
//# sourceMappingURL=AuthBlock.js.map