mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
Merge branch 'main' into post-to-zulip
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
function shouldShowError(error: Error | null | undefined) {
|
||||
if (error?.name == "ResponseError" && error["response"].status == 404)
|
||||
if (
|
||||
error?.name == "ResponseError" &&
|
||||
(error["response"].status == 404 || error["response"].status == 403)
|
||||
)
|
||||
return false;
|
||||
if (error?.name == "FetchError") return false;
|
||||
return true;
|
||||
|
||||
@@ -66,10 +66,6 @@ export const getFiefAuthMiddleware = async (url) => {
|
||||
matcher: "/transcripts",
|
||||
parameters: {},
|
||||
},
|
||||
{
|
||||
matcher: "/transcripts/((?!new).*)",
|
||||
parameters: {},
|
||||
},
|
||||
{
|
||||
matcher: "/browse",
|
||||
parameters: {},
|
||||
|
||||
@@ -4,17 +4,19 @@ import { DefaultApi } from "../api/apis/DefaultApi";
|
||||
import { useFiefAccessTokenInfo } from "@fief/fief/nextjs/react";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { DomainContext, featureEnabled } from "../[domain]/domainContext";
|
||||
import { CookieContext } from "../(auth)/fiefWrapper";
|
||||
|
||||
export default function getApi(protectedPath: boolean): DefaultApi | undefined {
|
||||
export default function getApi(): DefaultApi | undefined {
|
||||
const accessTokenInfo = useFiefAccessTokenInfo();
|
||||
const api_url = useContext(DomainContext).api_url;
|
||||
const requireLogin = featureEnabled("requireLogin");
|
||||
const [api, setApi] = useState<DefaultApi>();
|
||||
const { hasAuthCookie } = useContext(CookieContext);
|
||||
|
||||
if (!api_url) throw new Error("no API URL");
|
||||
|
||||
useEffect(() => {
|
||||
if (protectedPath && requireLogin && !accessTokenInfo) {
|
||||
if (hasAuthCookie && requireLogin && !accessTokenInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ export default function getApi(protectedPath: boolean): DefaultApi | undefined {
|
||||
: undefined,
|
||||
});
|
||||
setApi(new DefaultApi(apiConfiguration));
|
||||
}, [!accessTokenInfo, protectedPath]);
|
||||
}, [!accessTokenInfo, hasAuthCookie]);
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user