Skip to content

Commit

Permalink
Merge pull request #56 from iotum/jerry_hu/handle-session-expired
Browse files Browse the repository at this point in the history
handle session expired
  • Loading branch information
jerry2013 authored Sep 12, 2024
2 parents ea84b9a + 281699a commit c99f6b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/LoadingWidget.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";

const LoadingWidget = ({ id = undefined, className = undefined, error = undefined, children = undefined }) => {
const LoadingWidget = ({ id = undefined, className = undefined, error = undefined, isLoading = true, children = undefined }) => {
const [time, setTime] = useState(1);

useEffect(() => {
Expand All @@ -11,6 +11,10 @@ const LoadingWidget = ({ id = undefined, className = undefined, error = undefine
return () => clearInterval(interval);
}, [error]);

if (!isLoading && !error) {
return null;
}

return (
<div id={id} className={className}>
{
Expand Down
8 changes: 7 additions & 1 deletion src/pages/tabbed-dashboard/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ const App = () => {
});
});

widget.on('dashboard.SESSION_EXPIRED', () => {
console.error('Widget error:', 'Session expired');
setError('Session expired');
});

widget.on('widget.ERROR', (error) => {
// e.g. when the user is not authorized to access the widget
console.error('Widget error:', error);
setError(JSON.stringify(error));
});
Expand Down Expand Up @@ -245,7 +251,7 @@ const App = () => {
</Tab>
))
}
{!isWidgetInitialized && <LoadingWidget error={error} />}
<LoadingWidget error={error} isLoading={!isWidgetInitialized} />
</div>
{isYourAppVisible && (<div>Your app goes here</div>)}
<TokenButton position='right' />
Expand Down

0 comments on commit c99f6b9

Please sign in to comment.