Commit 52192b0a authored by TJHeeringa's avatar TJHeeringa

Likely fix for Restful-react provider sunmember=null issue

parent c09c845d
import React from "react";
import {RestfulProvider} from "restful-react";
import {useAuth} from "./Authentication";
......
......@@ -14,10 +14,11 @@ import {Home} from "../../Pages/Home/Home";
import SharedProfile from "../../Pages/Profile/SharedProfile";
import {Associations} from "../../Pages/Search/Associations";
import {AssociationRoutes} from "./MyAssociations/Association";
import {useAuth} from "../../Contexts/Authentication";
export const AuthorizedRoutes = (props) => {
const location = useLocation();
const authenticator = useAuth();
const url = "/protected";
let { data: sunmember, loading: loadingSunMember, refetch, error } = useGet({
......@@ -30,6 +31,12 @@ export const AuthorizedRoutes = (props) => {
);
}
// The restful provider from restful-react does no a nice catch, when the response is `status 401, credentials invalid`
// hence we need to do that here manually. This is no issue elsewhere, since this is the first query done.
if (sunmember === null) {
authenticator.logout();
}
const number_of_profiles = sunmember.profiles.length;
const preferred_profile_set = sunmember.preferred_profile !== undefined;
const claimed_memberships = sunmember.association_memberships.filter(membership => membership.status === "claimed");
......
import React from "react";
import {Redirect} from "react-router-dom";
import {useAuth} from "../../Contexts/Authentication";
const OIDC = (props) => {
const authenticator = useAuth();
authenticator.login("OIDC");
localStorage.setItem("SUN_backend", "OIDC");
localStorage.setItem("authenticated", "true");
authenticator.login("OIDC", {});
return <Redirect to={{ pathname: "/protected/v/home" }}/>;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment