diff --git a/scm-ui/src/containers/Login.js b/scm-ui/src/containers/Login.js index e70afe14d2..70d994f21e 100644 --- a/scm-ui/src/containers/Login.js +++ b/scm-ui/src/containers/Login.js @@ -18,7 +18,7 @@ import { Image } from "@scm-manager/ui-components"; import classNames from "classnames"; -import { fetchIndexResources } from "../modules/indexResource"; +import { fetchIndexResources, getLoginLink } from "../modules/indexResource"; const styles = { avatar: { @@ -42,9 +42,10 @@ type Props = { authenticated: boolean, loading: boolean, error: Error, + loginLink: string, // dispatcher props - login: (username: string, password: string) => void, + login: (link: string, username: string, password: string) => void, fetchIndexResources: () => void, // context props @@ -76,7 +77,11 @@ class Login extends React.Component { handleSubmit = (event: Event) => { event.preventDefault(); if (this.isValid()) { - this.props.login(this.state.username, this.state.password); + this.props.login( + this.props.loginLink, + this.state.username, + this.state.password + ); } }; @@ -148,17 +153,19 @@ const mapStateToProps = state => { const authenticated = isAuthenticated(state); const loading = isLoginPending(state); const error = getLoginFailure(state); + const loginLink = getLoginLink(state); return { authenticated, loading, - error + error, + loginLink }; }; const mapDispatchToProps = dispatch => { return { - login: (username: string, password: string) => - dispatch(login(username, password)), + login: (link: string, username: string, password: string) => + dispatch(login(link, username, password)), fetchIndexResources: () => dispatch(fetchIndexResources()) }; }; diff --git a/scm-ui/src/modules/auth.js b/scm-ui/src/modules/auth.js index add4d879ce..203c33493f 100644 --- a/scm-ui/src/modules/auth.js +++ b/scm-ui/src/modules/auth.js @@ -125,7 +125,6 @@ export const fetchMeFailure = (error: Error) => { // urls const ME_URL = "/me"; -const LOGIN_URL = "/auth/access_token"; // side effects @@ -140,7 +139,7 @@ const callFetchMe = (): Promise => { }); }; -export const login = (username: string, password: string) => { +export const login = (link: string, username: string, password: string) => { const login_data = { cookie: true, grant_type: "password", @@ -150,7 +149,7 @@ export const login = (username: string, password: string) => { return function(dispatch: any) { dispatch(loginPending()); return apiClient - .post(LOGIN_URL, login_data) + .post(link, login_data) .then(response => { return callFetchMe(); }) diff --git a/scm-ui/src/modules/auth.test.js b/scm-ui/src/modules/auth.test.js index 23f0ffe83b..5ece8a715a 100644 --- a/scm-ui/src/modules/auth.test.js +++ b/scm-ui/src/modules/auth.test.js @@ -100,9 +100,11 @@ describe("auth actions", () => { const store = mockStore({}); - return store.dispatch(login("tricia", "secret123")).then(() => { - expect(store.getActions()).toEqual(expectedActions); - }); + return store + .dispatch(login("/auth/access_token", "tricia", "secret123")) + .then(() => { + expect(store.getActions()).toEqual(expectedActions); + }); }); it("should dispatch login failure", () => { @@ -111,12 +113,14 @@ describe("auth actions", () => { }); const store = mockStore({}); - return store.dispatch(login("tricia", "secret123")).then(() => { - const actions = store.getActions(); - expect(actions[0].type).toEqual(LOGIN_PENDING); - expect(actions[1].type).toEqual(LOGIN_FAILURE); - expect(actions[1].payload).toBeDefined(); - }); + return store + .dispatch(login("/auth/access_token", "tricia", "secret123")) + .then(() => { + const actions = store.getActions(); + expect(actions[0].type).toEqual(LOGIN_PENDING); + expect(actions[1].type).toEqual(LOGIN_FAILURE); + expect(actions[1].payload).toBeDefined(); + }); }); it("should dispatch fetch me success", () => {