mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Fix redirect after logout
This commit is contained in:
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
### Fixed
|
||||||
|
- Fix redirect after logout if is set
|
||||||
|
|
||||||
## [2.14.0] - 2021-03-01
|
## [2.14.0] - 2021-03-01
|
||||||
### Added
|
### Added
|
||||||
- Repository data can be migrated independently to enable the import of dumps from older versions ([#1526](https://github.com/scm-manager/scm-manager/pull/1526))
|
- Repository data can be migrated independently to enable the import of dumps from older versions ([#1526](https://github.com/scm-manager/scm-manager/pull/1526))
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ describe("Test login hooks", () => {
|
|||||||
const queryClient = createInfiniteCachingClient();
|
const queryClient = createInfiniteCachingClient();
|
||||||
setIndexLink(queryClient, "logout", "/logout");
|
setIndexLink(queryClient, "logout", "/logout");
|
||||||
|
|
||||||
fetchMock.deleteOnce("/api/v2/logout", "");
|
fetchMock.deleteOnce("/api/v2/logout", {});
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useLogout(), {
|
const { result, waitForNextUpdate } = renderHook(() => useLogout(), {
|
||||||
wrapper: createWrapper(undefined, queryClient)
|
wrapper: createWrapper(undefined, queryClient)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Me } from "@scm-manager/ui-types";
|
import { Me } from "@scm-manager/ui-types";
|
||||||
|
import { useEffect } from "react";
|
||||||
import { useMutation, useQuery } from "react-query";
|
import { useMutation, useQuery } from "react-query";
|
||||||
import { apiClient } from "./apiclient";
|
import { apiClient } from "./apiclient";
|
||||||
import { ApiResult, useIndexLink } from "./base";
|
import { ApiResult, useIndexLink } from "./base";
|
||||||
@@ -95,21 +96,31 @@ export const useLogin = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type LogoutResponse = {
|
||||||
|
logoutRedirect?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const useLogout = () => {
|
export const useLogout = () => {
|
||||||
const link = useIndexLink("logout");
|
const link = useIndexLink("logout");
|
||||||
const reset = useReset();
|
const reset = useReset();
|
||||||
|
|
||||||
const { mutate, isLoading, error, data } = useMutation<boolean, Error, unknown>(
|
const { mutate, isLoading, error, data } = useMutation<LogoutResponse, Error, unknown>(() =>
|
||||||
() => apiClient.delete(link!).then(() => true),
|
apiClient.delete(link!).then(r => (r.status === 200 ? r.json() : {}))
|
||||||
{
|
|
||||||
onSuccess: reset
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
mutate({});
|
mutate({});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data?.logoutRedirect) {
|
||||||
|
window.location.assign(data.logoutRedirect);
|
||||||
|
}
|
||||||
|
if (data) {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}, [data, reset]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
logout: link && !data ? logout : undefined,
|
logout: link && !data ? logout : undefined,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
|||||||
Reference in New Issue
Block a user