Skip to content

Commit

Permalink
feat: introduces authorization_parameters error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jbottigliero committed Mar 14, 2024
1 parent f53d442 commit 0f76136
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
1 change: 0 additions & 1 deletion components/file-browser/FileBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export default function FileBrowser({
type: "RESET_ITEMS",
});
}
console.log(fileBrowser.view.show_hidden);
const response = await transfer.fileOperations.ls(collection, {
headers: {
Authorization: `Bearer ${auth.authorization?.tokens.transfer?.access_token}`,
Expand Down
50 changes: 20 additions & 30 deletions components/file-browser/FileBrowserError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from "@chakra-ui/react";

import { useGlobusAuth } from "../globus-auth-context/useGlobusAuth";

import {
isErrorWellFormed,
isConsentRequiredError,
isAuthorizationRequirementsError,
} from "@globus/sdk/cjs/lib/core/authorization/AuthorizationManager";
import type { DirectoryListingError } from "@globus/sdk/cjs/lib/services/transfer/service/file-operations";

export default function FileBrowserError({
Expand All @@ -24,20 +28,9 @@ export default function FileBrowserError({
}) {
const auth = useGlobusAuth();

const isWellFormedError = (
error: unknown,
): error is DirectoryListingError => {
return (
typeof error === "object" &&
error !== null &&
"code" in error &&
"message" in error
);
};

const isDirectoryListingError = isWellFormedError(error);
const isWellFormed = isErrorWellFormed(error);

if (isDirectoryListingError && error.code === "ConsentRequired") {
if (isWellFormed && isConsentRequiredError(error)) {
return (
<Alert status="warning">
<Box>
Expand Down Expand Up @@ -65,11 +58,7 @@ export default function FileBrowserError({
);
}

if (
isDirectoryListingError &&
error.code === "PermissionDenied" &&
"authorization_parameters" in error
) {
if (isWellFormed && isAuthorizationRequirementsError(error)) {
/* eslint-disable camelcase */
const {
session_message,
Expand All @@ -83,15 +72,14 @@ export default function FileBrowserError({
<Box>
<HStack>
<AlertIcon />
<AlertTitle>{error.message}</AlertTitle>
<AlertTitle>{session_message || error.message}</AlertTitle>
</HStack>
<AlertDescription>
{session_message && <Text my={2}>{session_message}</Text>}
<List>
<List p={2}>
{session_required_mfa && (
<ListItem>Requires Multi-Factor Authentication</ListItem>
)}
{session_required_identities && (
{session_required_identities?.length && (
<ListItem>
<Text as="strong">Required Identities:</Text>{" "}
{session_required_identities.join(", ")}
Expand All @@ -100,18 +88,20 @@ export default function FileBrowserError({
{session_required_single_domain &&
session_required_single_domain?.length && (
<ListItem>
<Text as="strong">Required Single Domain:</Text>{" "}
<Text as="strong">Required Domain(s):</Text>{" "}
{session_required_single_domain}
</ListItem>
)}
</List>
{/* <Button
onClick={() => auth.authorization?.login()}
<Button
onClick={() =>
auth.authorization?.handleAuthorizationRequirementsError(error)
}
colorScheme="brand"
size="sm"
>
Continue
</Button> */}
Address
</Button>
<Code
bgColor="red.50"
display="block"
Expand All @@ -128,7 +118,7 @@ export default function FileBrowserError({
/* eslint-enable camelcase */
}

if (isDirectoryListingError && error.code === "AuthenticationFailed") {
if (isWellFormed && error.code === "AuthenticationFailed") {
return (
<Alert status="error">
<Box>
Expand All @@ -153,7 +143,7 @@ export default function FileBrowserError({
);
}

if (isDirectoryListingError) {
if (isWellFormed) {
return (
<Alert status="error" flexDirection="column">
<Box>
Expand Down
1 change: 0 additions & 1 deletion components/file-browser/FileBrowserViewMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default function FileBrowserViewMenu() {
type="checkbox"
defaultValue={[state.view.show_hidden ? "show_hidden" : ""]}
onChange={(value) => {
console.log(value);
dispatch({
type: "SET_VIEW_SHOW_HIDDEN",
payload: value.includes("show_hidden"),
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@globus/sdk": "^3.0.0-alpha.4",
"@globus/sdk": "^3.0.0-alpha.5",
"framer-motion": "^11.0.5",
"next": "14.1.0",
"react": "^18",
Expand Down

0 comments on commit 0f76136

Please sign in to comment.