mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
Fix missing redirect after login (#1592)
Each unauthorized error was caught by the token expired handler, which has reset the whole query state and this leads sometimes to a missing redirect after login.
This commit is contained in:
@@ -23,7 +23,15 @@
|
||||
*/
|
||||
|
||||
import { contextPath } from "./urls";
|
||||
import { BackendErrorContent, createBackendError, ForbiddenError, isBackendError, UnauthorizedError } from "./errors";
|
||||
import {
|
||||
BackendErrorContent,
|
||||
createBackendError,
|
||||
ForbiddenError,
|
||||
isBackendError,
|
||||
TOKEN_EXPIRED_ERROR_CODE,
|
||||
TokenExpiredError,
|
||||
UnauthorizedError
|
||||
} from "./errors";
|
||||
|
||||
type SubscriptionEvent = {
|
||||
type: string;
|
||||
@@ -119,6 +127,15 @@ const applyFetchOptions: (p: RequestInit) => RequestInit = o => {
|
||||
function handleFailure(response: Response) {
|
||||
if (!response.ok) {
|
||||
if (response.status === 401) {
|
||||
if (isBackendError(response)) {
|
||||
return response.json().then((content: BackendErrorContent) => {
|
||||
if (content.errorCode === TOKEN_EXPIRED_ERROR_CODE) {
|
||||
throw new TokenExpiredError("Token expired", 401);
|
||||
} else {
|
||||
throw new UnauthorizedError("Unauthorized", 401);
|
||||
}
|
||||
});
|
||||
}
|
||||
throw new UnauthorizedError("Unauthorized", 401);
|
||||
} else if (response.status === 403) {
|
||||
throw new ForbiddenError("Forbidden", 403);
|
||||
|
||||
@@ -72,14 +72,18 @@ export class BackendError extends Error {
|
||||
|
||||
export class UnauthorizedError extends Error {
|
||||
statusCode: number;
|
||||
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
export class TokenExpiredError extends UnauthorizedError {}
|
||||
|
||||
export class ForbiddenError extends Error {
|
||||
statusCode: number;
|
||||
|
||||
constructor(message: string, statusCode: number) {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
import { Me } from "@scm-manager/ui-types";
|
||||
import { useEffect } from "react";
|
||||
import { useMutation, useQuery } from "react-query";
|
||||
import { apiClient } from "./apiclient";
|
||||
import { ApiResult, useIndexLink } from "./base";
|
||||
@@ -111,7 +110,7 @@ export const useLogout = () => {
|
||||
if (response?.logoutRedirect) {
|
||||
window.location.assign(response.logoutRedirect);
|
||||
}
|
||||
reset();
|
||||
return reset();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user