From e809a2661726077dca84953c2ea37315d2b1c2df Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 29 Feb 2024 09:30:20 -0600 Subject: [PATCH 1/6] fix: external auth device flow, check both queries for errors --- site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx b/site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx index 74d188f7f14da..ac818cf848411 100644 --- a/site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx +++ b/site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx @@ -53,6 +53,8 @@ const ExternalAuthPage: FC = () => { if (isAxiosError(exchangeExternalAuthDeviceQuery.failureReason)) { deviceExchangeError = exchangeExternalAuthDeviceQuery.failureReason.response?.data; + } else if (isAxiosError(externalAuthDeviceQuery.failureReason)) { + deviceExchangeError = externalAuthDeviceQuery.failureReason.response?.data; } if ( From 6ea918888878873f6c07491f711abea94501369d Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 29 Feb 2024 09:33:37 -0600 Subject: [PATCH 2/6] This is a terrible fix --- .../pages/ExternalAuthPage/ExternalAuthPageView.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx index 5185b316ffe81..d0abcf63a8a22 100644 --- a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx +++ b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx @@ -181,10 +181,21 @@ const GitDeviceAuth: FC = ({ } } - if (!externalAuthDevice) { + if (!externalAuthDevice && !deviceExchangeError) { return ; } + // This is a terrible fix. If `externalAuthDevice` fails, then we have an error and no code. + if (!externalAuthDevice) { + externalAuthDevice = { + user_code: "", + verification_uri: "", + device_code: "", + expires_in: 0, + interval: 0, + }; + } + return (

From 00a761df96d8756af120bc2425d4cb92af595898 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 29 Feb 2024 09:35:37 -0600 Subject: [PATCH 3/6] Handle error more gracefully in the code --- .../ExternalAuthPage/ExternalAuthPageView.tsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx index d0abcf63a8a22..31c8c0753c984 100644 --- a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx +++ b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx @@ -181,19 +181,14 @@ const GitDeviceAuth: FC = ({ } } - if (!externalAuthDevice && !deviceExchangeError) { - return ; + // If the error comes from the `externalAuthDevice` query, + // we cannot even display the user_code. + if (deviceExchangeError && !externalAuthDevice) { + return

{status}
; } - // This is a terrible fix. If `externalAuthDevice` fails, then we have an error and no code. if (!externalAuthDevice) { - externalAuthDevice = { - user_code: "", - verification_uri: "", - device_code: "", - expires_in: 0, - interval: 0, - }; + return ; } return ( From 14baf026d61fcb325f36d5b77935a6fa6c32413e Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 29 Feb 2024 09:38:23 -0600 Subject: [PATCH 4/6] Show details in the error --- site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx index 31c8c0753c984..6d836daecf6b7 100644 --- a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx +++ b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx @@ -175,6 +175,12 @@ const GitDeviceAuth: FC = ({ An unknown error occurred. Please try again:{" "} {deviceExchangeError.message} + {deviceExchangeError.detail && ( + +
+ Details: {deviceExchangeError.detail ?? ""} +
+ )}
); break; From 404c05c8aa36a673db9641aab977e0228a9f3b5b Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 29 Feb 2024 09:41:46 -0600 Subject: [PATCH 5/6] Add 429 storybook --- .../ExternalAuthPageView.stories.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.stories.tsx b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.stories.tsx index 8b8f3d57c5300..eec8dd76c82b4 100644 --- a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.stories.tsx +++ b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.stories.tsx @@ -49,6 +49,27 @@ DeviceUnauthenticated.args = { }, }; +export const Device429Error = Template.bind({}); +Device429Error.args = { + externalAuth: { + display_name: "GitHub", + authenticated: false, + device: true, + installations: [], + app_install_url: "", + app_installable: false, + }, + // This is intentionally undefined. + // If we get a 429 on the first /device call, then this + // is undefined with a 429 error. + externalAuthDevice: undefined, + deviceExchangeError: { + message: "Failed to authorize device.", + detail: + "rate limit hit, unable to authorize device. please try again later", + }, +}; + export const DeviceUnauthenticatedError = Template.bind({}); DeviceUnauthenticatedError.args = { externalAuth: { From fb6b5453660cfdd1ab172496e0c6ce6e6fea4591 Mon Sep 17 00:00:00 2001 From: BrunoQuaresma Date: Thu, 29 Feb 2024 18:49:49 +0000 Subject: [PATCH 6/6] Minor style update --- .../pages/ExternalAuthPage/ExternalAuthPageView.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx index 6d836daecf6b7..95773089cd126 100644 --- a/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx +++ b/site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx @@ -1,12 +1,13 @@ import { type Interpolation, type Theme } from "@emotion/react"; import OpenInNewIcon from "@mui/icons-material/OpenInNew"; import RefreshIcon from "@mui/icons-material/Refresh"; +import AlertTitle from "@mui/material/AlertTitle"; import CircularProgress from "@mui/material/CircularProgress"; import Link from "@mui/material/Link"; import Tooltip from "@mui/material/Tooltip"; import type { ApiErrorResponse } from "api/errors"; import type { ExternalAuth, ExternalAuthDevice } from "api/typesGenerated"; -import { Alert } from "components/Alert/Alert"; +import { Alert, AlertDetail } from "components/Alert/Alert"; import { Avatar } from "components/Avatar/Avatar"; import { CopyButton } from "components/CopyButton/CopyButton"; import { SignInLayout } from "components/SignInLayout/SignInLayout"; @@ -173,13 +174,9 @@ const GitDeviceAuth: FC = ({ default: status = ( - An unknown error occurred. Please try again:{" "} - {deviceExchangeError.message} + {deviceExchangeError.message} {deviceExchangeError.detail && ( - -
- Details: {deviceExchangeError.detail ?? ""} -
+ {deviceExchangeError.detail} )}
);