use logout link of index resource

This commit is contained in:
Maren Süwer
2018-10-11 08:27:24 +02:00
parent eb65ef1e65
commit 6562071bfe
3 changed files with 12 additions and 8 deletions

View File

@@ -11,14 +11,16 @@ import {
getLogoutFailure
} from "../modules/auth";
import { Loading, ErrorPage } from "@scm-manager/ui-components";
import { getLogoutLink } from "../modules/indexResource";
type Props = {
authenticated: boolean,
loading: boolean,
error: Error,
logoutLink: string,
// dispatcher functions
logout: () => void,
logout: (link: string) => void,
// context props
t: string => string
@@ -26,7 +28,7 @@ type Props = {
class Logout extends React.Component<Props> {
componentDidMount() {
this.props.logout();
this.props.logout(this.props.logoutLink);
}
render() {
@@ -51,16 +53,18 @@ const mapStateToProps = state => {
const authenticated = isAuthenticated(state);
const loading = isLogoutPending(state);
const error = getLogoutFailure(state);
const logoutLink = getLogoutLink(state);
return {
authenticated,
loading,
error
error,
logoutLink
};
};
const mapDispatchToProps = dispatch => {
return {
logout: () => dispatch(logout())
logout: (link: string) => dispatch(logout(link))
};
};

View File

@@ -180,11 +180,11 @@ export const fetchMe = () => {
};
};
export const logout = () => {
export const logout = (link: string) => {
return function(dispatch: any) {
dispatch(logoutPending());
return apiClient
.delete(LOGIN_URL)
.delete(link)
.then(() => {
dispatch(logoutSuccess());
})

View File

@@ -188,7 +188,7 @@ describe("auth actions", () => {
const store = mockStore({});
return store.dispatch(logout()).then(() => {
return store.dispatch(logout("/auth/access_token")).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
@@ -199,7 +199,7 @@ describe("auth actions", () => {
});
const store = mockStore({});
return store.dispatch(logout()).then(() => {
return store.dispatch(logout("/auth/access_token")).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual(LOGOUT_PENDING);
expect(actions[1].type).toEqual(LOGOUT_FAILURE);