refactor: rewrite to cookie based auth (#578)

* rewrite to cookie based auth

* remove interceptor

Former-commit-id: 1365bdfd46
This commit is contained in:
Hayden 2023-10-06 22:44:43 -05:00 committed by GitHub
parent 36e13ab03b
commit c71f077466
8 changed files with 155 additions and 71 deletions

View file

@ -30,12 +30,15 @@ export function usePublicApi(): PublicApi {
export function useUserApi(): UserClient {
const authCtx = useAuthContext();
const requests = new Requests("", () => authCtx.token || "", {});
const requests = new Requests("", "", {});
requests.addResponseInterceptor(logger);
requests.addResponseInterceptor(r => {
if (r.status === 401) {
console.error("unauthorized request, invalidating session");
authCtx.invalidateSession();
if (window.location.pathname !== "/") {
window.location.href = "/";
}
}
});