Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit

Permalink
chore: remove workaround for badgateway/oauth2-client#110
Browse files Browse the repository at this point in the history
  • Loading branch information
debater-coder committed Aug 9, 2023
1 parent c1700fe commit 9e7d635
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 202 deletions.
2 changes: 1 addition & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"setup": "pnpm install && pnpm validate"
},
"dependencies": {
"@badgateway/oauth2-client": "^2.2.1",
"@badgateway/oauth2-client": "^2.2.3",
"@chakra-ui/icons": "^2.0.19",
"@chakra-ui/react": "^2.7.1",
"@chakra-ui/theme-tools": "^2.0.18",
Expand Down
19 changes: 14 additions & 5 deletions apps/client/src/routes/Main/Home/Cycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Center,
Spinner,
Spacer,
Button,
} from "@chakra-ui/react";
import { useTimetable } from "../../../services/sbhsApi/useTimetable";
import { TimetableDay } from "../../../services/sbhsApi/schemas";
Expand All @@ -19,25 +20,33 @@ function Period(props: {
activeSubject: string | null;
}) {
const isActive = props.activeSubject === props.period.title;
const highlightColor = useColorModeValue("primary.300", "primary.600");

return (
<Flex
direction={["column", "column", "row"]}
<Button
display="flex"
flexDirection={["column", "column", "row"]}
bg={useToken("colors", useColorModeValue("gray.300", "gray.700")) + "55"}
rounded={"lg"}
gap={1}
align="center"
alignItems="center"
fontFamily={"Poppins, sans-serif"}
variant="unstyled"
_hover={{
bg:
useToken("colors", useColorModeValue("gray.300", "gray.700")) + "ff",
}}
onClick={() =>
props.setActiveSubject(isActive ? null : props.period.title)
}
shadow={isActive ? "outline" : undefined}
height="auto"
>
<Text
fontSize={"sm"}
bg={
props.period.room && (isActive || props.activeSubject === null)
? "primary.500"
? highlightColor
: undefined
}
p={2}
Expand All @@ -51,7 +60,7 @@ function Period(props: {
<Text fontSize={"sm"} fontWeight={"bold"} pr={[0, 0, 2]}>
{props.period.room}
</Text>
</Flex>
</Button>
);
}

Expand Down
31 changes: 9 additions & 22 deletions apps/client/src/stores/auth/actions/fetchAuthenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { SbhsApiEndpoint } from "../../../services/sbhsApi/schemas";
import NetworkError from "../../../errors/NetworkError";
import HTTPError from "../../../errors/HTTPError";

let ready = false;

const initialiseFetchWrapper = async () => {
const fetchWrapper = new OAuth2Fetch({
const initialiseFetchWrapper = () =>
new OAuth2Fetch({
client: getClient(),

getNewToken: () => {
Expand All @@ -26,21 +24,11 @@ const initialiseFetchWrapper = async () => {
},

onError: (error) => {
if (ready) {
// Set the status to expired
useAuthStore.setState({ status: AuthStatus.EXPIRED });
console.error(error);
}
// Set the status to expired
useAuthStore.setState({ status: AuthStatus.EXPIRED });
console.error(error);
},
});
try {
await fetchWrapper.getToken();
} catch {
// Ignore we expect this to error because the library has a bug
}
ready = true;
return fetchWrapper;
};

let _fetchWrapper: OAuth2Fetch | null = null;

Expand All @@ -49,12 +37,11 @@ export const resetFetchWrapper = () => {
initialiseFetchWrapper();
};

// We defer initialisation until the first call to fetchAuthenticated to ensure that initialisation has been completed
const getFetchWrapper = async () => {
// We defer initialisation until the first call to fetchAuthenticated to ensure that any mocks have been set up
const getFetchWrapper = () => {
if (!_fetchWrapper) {
_fetchWrapper = await initialiseFetchWrapper();
_fetchWrapper = initialiseFetchWrapper();
}
6;

return _fetchWrapper;
};
Expand All @@ -68,7 +55,7 @@ export const fetchAuthenticated = async <TSbhsApiData>(
) => {
let res: Response;
try {
const fetchWrapper = await getFetchWrapper();
const fetchWrapper = getFetchWrapper();
res = await fetchWrapper.fetch(
"https://student.sbhs.net.au/api/" +
endpoint +
Expand Down
Loading

0 comments on commit 9e7d635

Please sign in to comment.