Skip to content

Commit

Permalink
chore: do not allow access to setup screen if service is running and …
Browse files Browse the repository at this point in the history
…locked
  • Loading branch information
rolznz committed Jan 31, 2024
1 parent b6071b6 commit 31beb23
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AppsRedirect } from "src/components/redirects/AppsRedirect";
import { StartRedirect } from "src/components/redirects/StartRedirect";
import { HomeRedirect } from "src/components/redirects/HomeRedirect";
import Unlock from "src/screens/Unlock";
import { SetupRedirect } from "src/components/redirects/SetupRedirect";

function App() {
return (
Expand All @@ -36,7 +37,7 @@ function App() {
}
></Route>
<Route path="welcome" element={<Welcome />}></Route>
<Route path="setup">
<Route path="setup" element={<SetupRedirect />}>
<Route path="" element={<Navigate to="password" replace />} />
<Route path="password" element={<SetupPassword />} />
<Route path="node" element={<SetupNode />} />
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/components/redirects/SetupRedirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useInfo } from "src/hooks/useInfo";
import { Outlet, useLocation, useNavigate } from "react-router-dom";
import React from "react";
import Loading from "src/components/Loading";

export function SetupRedirect() {
const { data: info } = useInfo();
const location = useLocation();
const navigate = useNavigate();

React.useEffect(() => {
if (!info) {
return;
}
if (info.running && !info.unlocked) {
navigate("/");
}
}, [info, location, navigate]);

if (!info) {
return <Loading />;
}

return <Outlet />;
}
4 changes: 4 additions & 0 deletions http_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ func (httpSvc *HttpService) setupHandler(c echo.Context) error {
})
}

if httpSvc.svc.lnClient != nil && !httpSvc.isUnlocked(c) {
return c.NoContent(http.StatusUnauthorized)
}

err := httpSvc.api.Setup(&setupRequest)
if err != nil {
return c.JSON(http.StatusInternalServerError, ErrorResponse{
Expand Down

0 comments on commit 31beb23

Please sign in to comment.