mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Introduce extension point for logout redirection
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
fetchIndexResourcesPending,
|
||||
fetchIndexResourcesSuccess
|
||||
} from "./indexResource";
|
||||
import type { History } from "history";
|
||||
|
||||
// Action
|
||||
|
||||
@@ -30,6 +31,10 @@ export const LOGOUT_PENDING = `${LOGOUT}_${types.PENDING_SUFFIX}`;
|
||||
export const LOGOUT_SUCCESS = `${LOGOUT}_${types.SUCCESS_SUFFIX}`;
|
||||
export const LOGOUT_FAILURE = `${LOGOUT}_${types.FAILURE_SUFFIX}`;
|
||||
|
||||
type LogoutRedirection = {
|
||||
logoutRedirect: string
|
||||
};
|
||||
|
||||
// Reducer
|
||||
|
||||
const initialState = {};
|
||||
@@ -130,11 +135,9 @@ export const fetchMeFailure = (error: Error) => {
|
||||
// side effects
|
||||
|
||||
const callFetchMe = (link: string): Promise<Me> => {
|
||||
return apiClient
|
||||
.get(link)
|
||||
.then(response => {
|
||||
return response.json();
|
||||
});
|
||||
return apiClient.get(link).then(response => {
|
||||
return response.json();
|
||||
});
|
||||
};
|
||||
|
||||
export const login = (
|
||||
@@ -187,13 +190,24 @@ export const fetchMe = (link: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const logout = (link: string) => {
|
||||
export const logout = (link: string, history: History) => {
|
||||
return function(dispatch: any) {
|
||||
dispatch(logoutPending());
|
||||
return apiClient
|
||||
.delete(link)
|
||||
.then(() => {
|
||||
dispatch(logoutSuccess());
|
||||
.then(response => {
|
||||
return response.status === 200
|
||||
? response.json()
|
||||
: new Promise(function(resolve) {
|
||||
resolve(undefined);
|
||||
});
|
||||
})
|
||||
.then(json => {
|
||||
if (json && json.logoutRedirect) {
|
||||
location.href = json.logoutRedirect;
|
||||
} else {
|
||||
dispatch(logoutSuccess());
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
dispatch(fetchIndexResources());
|
||||
|
||||
Reference in New Issue
Block a user