Skip to content

Commit 4006974

Browse files
EmyrkBrunoQuaresma
andauthored
fix: external auth device flow, check both queries for errors (coder#12367)
* fix: external auth device flow, check both queries for errors * Minor style update --------- Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
1 parent 9f3591a commit 4006974

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const ExternalAuthPage: FC = () => {
5353
if (isAxiosError(exchangeExternalAuthDeviceQuery.failureReason)) {
5454
deviceExchangeError =
5555
exchangeExternalAuthDeviceQuery.failureReason.response?.data;
56+
} else if (isAxiosError(externalAuthDeviceQuery.failureReason)) {
57+
deviceExchangeError = externalAuthDeviceQuery.failureReason.response?.data;
5658
}
5759

5860
if (

site/src/pages/ExternalAuthPage/ExternalAuthPageView.stories.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ DeviceUnauthenticated.args = {
4949
},
5050
};
5151

52+
export const Device429Error = Template.bind({});
53+
Device429Error.args = {
54+
externalAuth: {
55+
display_name: "GitHub",
56+
authenticated: false,
57+
device: true,
58+
installations: [],
59+
app_install_url: "",
60+
app_installable: false,
61+
},
62+
// This is intentionally undefined.
63+
// If we get a 429 on the first /device call, then this
64+
// is undefined with a 429 error.
65+
externalAuthDevice: undefined,
66+
deviceExchangeError: {
67+
message: "Failed to authorize device.",
68+
detail:
69+
"rate limit hit, unable to authorize device. please try again later",
70+
},
71+
};
72+
5273
export const DeviceUnauthenticatedError = Template.bind({});
5374
DeviceUnauthenticatedError.args = {
5475
externalAuth: {

site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { type Interpolation, type Theme } from "@emotion/react";
22
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
33
import RefreshIcon from "@mui/icons-material/Refresh";
4+
import AlertTitle from "@mui/material/AlertTitle";
45
import CircularProgress from "@mui/material/CircularProgress";
56
import Link from "@mui/material/Link";
67
import Tooltip from "@mui/material/Tooltip";
78
import type { ApiErrorResponse } from "api/errors";
89
import type { ExternalAuth, ExternalAuthDevice } from "api/typesGenerated";
9-
import { Alert } from "components/Alert/Alert";
10+
import { Alert, AlertDetail } from "components/Alert/Alert";
1011
import { Avatar } from "components/Avatar/Avatar";
1112
import { CopyButton } from "components/CopyButton/CopyButton";
1213
import { SignInLayout } from "components/SignInLayout/SignInLayout";
@@ -173,14 +174,22 @@ const GitDeviceAuth: FC<GitDeviceAuthProps> = ({
173174
default:
174175
status = (
175176
<Alert severity="error">
176-
An unknown error occurred. Please try again:{" "}
177-
{deviceExchangeError.message}
177+
<AlertTitle>{deviceExchangeError.message}</AlertTitle>
178+
{deviceExchangeError.detail && (
179+
<AlertDetail>{deviceExchangeError.detail}</AlertDetail>
180+
)}
178181
</Alert>
179182
);
180183
break;
181184
}
182185
}
183186

187+
// If the error comes from the `externalAuthDevice` query,
188+
// we cannot even display the user_code.
189+
if (deviceExchangeError && !externalAuthDevice) {
190+
return <div>{status}</div>;
191+
}
192+
184193
if (!externalAuthDevice) {
185194
return <CircularProgress />;
186195
}

0 commit comments

Comments
 (0)