From e5dcf7bddee265709199cbe0df9ae99fd4c067db Mon Sep 17 00:00:00 2001 From: Sonia Appasamy Date: Fri, 3 Nov 2023 13:38:01 -0400 Subject: [PATCH] client/web: move auth session creation out of /api/auth Splits auth session creation into two new endpoints: /api/auth/session/new - to request a new auth session /api/auth/session/wait - to block until user has completed auth url Updates tailscale/corp#14335 Signed-off-by: Sonia Appasamy --- client/web/src/components/app.tsx | 12 +- .../components/views/readonly-client-view.tsx | 14 ++- client/web/src/hooks/auth.ts | 39 +++++-- client/web/web.go | 102 +++++++++++------ client/web/web_test.go | 106 ++++++++++-------- 5 files changed, 176 insertions(+), 97 deletions(-) diff --git a/client/web/src/components/app.tsx b/client/web/src/components/app.tsx index edbd885aa..488abedca 100644 --- a/client/web/src/components/app.tsx +++ b/client/web/src/components/app.tsx @@ -3,19 +3,19 @@ import React from "react" import LegacyClientView from "src/components/views/legacy-client-view" import LoginClientView from "src/components/views/login-client-view" import ReadonlyClientView from "src/components/views/readonly-client-view" -import useAuth, { AuthResponse } from "src/hooks/auth" +import useAuth, { AuthResponse, SessionsCallbacks } from "src/hooks/auth" import useNodeData from "src/hooks/node-data" import ManagementClientView from "./views/management-client-view" export default function App() { - const { data: auth, loading: loadingAuth, waitOnAuth } = useAuth() + const { data: auth, loading: loadingAuth, sessions } = useAuth() return (
{loadingAuth ? (
Loading...
// TODO(sonia): add a loading view ) : ( - + )}
) @@ -23,10 +23,10 @@ export default function App() { function WebClient({ auth, - waitOnAuth, + sessions, }: { auth?: AuthResponse - waitOnAuth: () => Promise + sessions: SessionsCallbacks }) { const { data, refreshData, updateNode } = useNodeData() @@ -45,7 +45,7 @@ function WebClient({ ) : data.DebugMode === "login" || data.DebugMode === "full" ? ( // Render new client interface in readonly mode. - + ) : ( // Render legacy client interface. Promise + sessions: SessionsCallbacks }) { return ( <> @@ -51,12 +51,14 @@ export default function ReadonlyClientView({
{data.IP}
- {data.DebugMode === "full" && ( + {auth?.authNeeded == AuthType.tailscale && (