diff --git a/scm-ui/src/containers/App.js b/scm-ui/src/containers/App.js index f99536618c..fb579acc3f 100644 --- a/scm-ui/src/containers/App.js +++ b/scm-ui/src/containers/App.js @@ -26,6 +26,7 @@ import { getFetchIndexResourcesFailure, getGroupsLink, getLogoutLink, + getMeLink, getRepositoriesLink, getUsersLink, isFetchIndexResourcesPending @@ -36,14 +37,15 @@ type Props = { authenticated: boolean, error: Error, loading: boolean, - repositoriesLink: String, - usersLink: String, - groupsLink: String, - configLink: String, - logoutLink: String, + repositoriesLink: string, + usersLink: string, + groupsLink: string, + configLink: string, + logoutLink: string, + meLink: string, // dispatcher functions - fetchMe: () => void, + fetchMe: (link: string) => void, fetchIndexResources: () => void, // context props @@ -52,8 +54,8 @@ type Props = { class App extends Component { componentDidMount() { - this.props.fetchIndexResources(); - this.props.fetchMe(); + //this.props.fetchIndexResources(); + if (this.props.meLink) this.props.fetchMe(this.props.meLink); } render() { @@ -108,7 +110,7 @@ class App extends Component { const mapDispatchToProps = (dispatch: any) => { return { - fetchMe: () => dispatch(fetchMe()), + fetchMe: (link: string) => dispatch(fetchMe(link)), fetchIndexResources: () => dispatch(fetchIndexResources()) }; }; @@ -125,6 +127,7 @@ const mapStateToProps = state => { const groupsLink = getGroupsLink(state); const configLink = getConfigLink(state); const logoutLink = getLogoutLink(state); + const meLink = getMeLink(state); return { authenticated, me, @@ -134,7 +137,8 @@ const mapStateToProps = state => { usersLink, groupsLink, configLink, - logoutLink + logoutLink, + meLink }; }; diff --git a/scm-ui/src/containers/Login.js b/scm-ui/src/containers/Login.js index 70d994f21e..df4484a539 100644 --- a/scm-ui/src/containers/Login.js +++ b/scm-ui/src/containers/Login.js @@ -18,7 +18,11 @@ import { Image } from "@scm-manager/ui-components"; import classNames from "classnames"; -import { fetchIndexResources, getLoginLink } from "../modules/indexResource"; +import { + fetchIndexResources, + getLoginLink, + getMeLink +} from "../modules/indexResource"; const styles = { avatar: { @@ -42,7 +46,7 @@ type Props = { authenticated: boolean, loading: boolean, error: Error, - loginLink: string, + link: string, // dispatcher props login: (link: string, username: string, password: string) => void, @@ -78,7 +82,7 @@ class Login extends React.Component { event.preventDefault(); if (this.isValid()) { this.props.login( - this.props.loginLink, + this.props.link, this.state.username, this.state.password ); @@ -94,7 +98,6 @@ class Login extends React.Component { } renderRedirect = () => { - this.props.fetchIndexResources(); const { from } = this.props.location.state || { from: { pathname: "/" } }; return ; }; @@ -153,20 +156,19 @@ const mapStateToProps = state => { const authenticated = isAuthenticated(state); const loading = isLoginPending(state); const error = getLoginFailure(state); - const loginLink = getLoginLink(state); + const link = getLoginLink(state); return { authenticated, loading, error, - loginLink + link }; }; const mapDispatchToProps = dispatch => { return { login: (link: string, username: string, password: string) => - dispatch(login(link, username, password)), - fetchIndexResources: () => dispatch(fetchIndexResources()) + dispatch(login(link, username, password)) }; }; diff --git a/scm-ui/src/index.js b/scm-ui/src/index.js index 511252620a..c00048be36 100644 --- a/scm-ui/src/index.js +++ b/scm-ui/src/index.js @@ -1,7 +1,7 @@ // @flow import React from "react"; import ReactDOM from "react-dom"; -import App from "./containers/App"; +import Index from "./containers/Index"; import registerServiceWorker from "./registerServiceWorker"; import { I18nextProvider } from "react-i18next"; @@ -38,7 +38,7 @@ ReactDOM.render( {/* ConnectedRouter will use the store from Provider automatically */} - + diff --git a/scm-ui/src/modules/auth.js b/scm-ui/src/modules/auth.js index 203c33493f..dd7971ba74 100644 --- a/scm-ui/src/modules/auth.js +++ b/scm-ui/src/modules/auth.js @@ -5,7 +5,7 @@ import * as types from "./types"; import { apiClient, UNAUTHORIZED_ERROR } from "@scm-manager/ui-components"; import { isPending } from "./pending"; import { getFailure } from "./failure"; -import { getMeLink } from "./indexResource"; +import { fetchIndexResources, getMeLink } from "./indexResource"; // Action @@ -128,9 +128,10 @@ const ME_URL = "/me"; // side effects -const callFetchMe = (): Promise => { +const callFetchMe = (link: string): Promise => { + console.log(link); return apiClient - .get(ME_URL) + .get(link) .then(response => { return response.json(); }) @@ -139,7 +140,11 @@ const callFetchMe = (): Promise => { }); }; -export const login = (link: string, username: string, password: string) => { +export const login = ( + loginLink: string, + username: string, + password: string +) => { const login_data = { cookie: true, grant_type: "password", @@ -149,9 +154,13 @@ export const login = (link: string, username: string, password: string) => { return function(dispatch: any) { dispatch(loginPending()); return apiClient - .post(link, login_data) + .post(loginLink, login_data) .then(response => { - return callFetchMe(); + return dispatch(fetchIndexResources()); + }) + .then(response => { + const meLink = response._links.me.href; + return dispatch(callFetchMe(meLink)); }) .then(me => { dispatch(loginSuccess(me)); @@ -162,10 +171,10 @@ export const login = (link: string, username: string, password: string) => { }; }; -export const fetchMe = () => { +export const fetchMe = (link: string) => { return function(dispatch: any) { dispatch(fetchMePending()); - return callFetchMe() + return callFetchMe(link) .then(me => { dispatch(fetchMeSuccess(me)); }) diff --git a/scm-ui/src/modules/auth.test.js b/scm-ui/src/modules/auth.test.js index 5ece8a715a..848e64d7c7 100644 --- a/scm-ui/src/modules/auth.test.js +++ b/scm-ui/src/modules/auth.test.js @@ -139,7 +139,7 @@ describe("auth actions", () => { const store = mockStore({}); - return store.dispatch(fetchMe()).then(() => { + return store.dispatch(fetchMe("me")).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -150,7 +150,7 @@ describe("auth actions", () => { }); const store = mockStore({}); - return store.dispatch(fetchMe()).then(() => { + return store.dispatch(fetchMe("me")).then(() => { const actions = store.getActions(); expect(actions[0].type).toEqual(FETCH_ME_PENDING); expect(actions[1].type).toEqual(FETCH_ME_FAILURE); @@ -170,7 +170,7 @@ describe("auth actions", () => { const store = mockStore({}); - return store.dispatch(fetchMe()).then(() => { + return store.dispatch(fetchMe("me")).then(() => { // return of async actions expect(store.getActions()).toEqual(expectedActions); });