feat(web): consume the :PiWeb login handoff before the first route
The daemon hands the browser `http://127.0.0.1:<port>/#t=<token>`. The token is read once, stored through the connection store (so the `pi2-connection` marker is set too and a fresh browser does not bounce to /connect), and stripped from the address bar and history while the query string survives.
This commit is contained in:
1 parent
9ab0830223
commit
51ef1c250b
3 files changed
+184
No files matched your search
@@ -8,7 +8,9 @@ import "@/styles/app.css";
|
||||
import "@/lib/i18n";
|
||||
|
||||
import { Toaster } from "@/components/ui/toast";
|
||||
import { consumeHandoff } from "@/lib/handoff";
|
||||
import { router } from "@/router";
|
||||
import { useConnectionStore } from "@/stores/connection";
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -39,6 +41,14 @@ function App() {
|
||||
);
|
||||
}
|
||||
|
||||
// `:PiWeb` hands the device token over in the fragment. Consume it before the
|
||||
// router resolves its first route, and go through the connection store (not
|
||||
// `setDeviceToken`) so the `pi2-connection` marker the guards read is set too:
|
||||
// otherwise a fresh browser would still bounce to `/connect` on its first load.
|
||||
consumeHandoff(window.location, window.history, (token) => {
|
||||
useConnectionStore.getState().connect({ token, endpoint: window.location.origin });
|
||||
});
|
||||
|
||||
const container = document.getElementById("root");
|
||||
if (!container) throw new Error("Missing #root element");
|
||||
createRoot(container).render(<App />);
|
||||
Reference in new issue
Block a user