@@ -8,6 +8,7 @@ import projectRoutes from './projects/routes.jsx'
88import RedirectComponent from './components/RedirectComponent'
99import { ACCOUNTS_APP_LOGIN_URL , PROJECT_FEED_TYPE_PRIMARY , PROJECT_FEED_TYPE_MESSAGES } from './config/constants'
1010import { getTopic } from './api/messages'
11+ import { getFreshToken } from 'tc-accounts'
1112
1213// import reportsListRoutes from './reports/routes.jsx'
1314
@@ -17,26 +18,33 @@ const LoginRedirect = withProps({
1718
1819const redirectToProject = ( nextState , replace , callback ) => {
1920 const feedId = nextState . params . feedId
20- getTopic ( feedId ) . then ( resp => {
21- if ( resp . topics && resp . topics . length > 0 ) {
22- const topic = resp . topics [ 0 ]
23- const projectId = topic . referenceId
24- if ( topic . tag === PROJECT_FEED_TYPE_PRIMARY ) {
25- replace ( `/projects/${ projectId } /` )
26- } else if ( topic . tag === PROJECT_FEED_TYPE_MESSAGES ) {
27- replace ( {
28- pathname : `/projects/${ projectId } /discussions` ,
29- state : { threadId : topic . id }
30- } )
31- } else {
32- replace ( '/projects' )
21+ getFreshToken ( ) . then ( ( ) => {
22+ getTopic ( feedId ) . then ( resp => {
23+ if ( resp . topics && resp . topics . length > 0 ) {
24+ const topic = resp . topics [ 0 ]
25+ const projectId = topic . referenceId
26+ if ( topic . tag === PROJECT_FEED_TYPE_PRIMARY ) {
27+ replace ( `/projects/${ projectId } /` )
28+ } else if ( topic . tag === PROJECT_FEED_TYPE_MESSAGES ) {
29+ replace ( {
30+ pathname : `/projects/${ projectId } /discussions` ,
31+ state : { threadId : topic . id }
32+ } )
33+ } else {
34+ replace ( '/projects' )
35+ }
3336 }
34- }
35- callback ( )
36- } )
37- . catch ( ( ) => {
38- replace ( '/projects' )
39- callback ( )
37+ callback ( )
38+ } )
39+ . catch ( ( ) => {
40+ replace ( '/projects' )
41+ callback ( )
42+ } )
43+ } ) . catch ( ( ) => {
44+ // FIXME should we include hash, search etc
45+ const redirectBackToUrl = window . location . origin + '/' + nextState . location . pathname
46+ const newLocation = ACCOUNTS_APP_LOGIN_URL + '?retUrl=' + redirectBackToUrl
47+ window . location = newLocation
4048 } )
4149}
4250
@@ -53,4 +61,4 @@ export default (
5361 < Route path = "/error" component = { ( ) => < PageError code = { 500 } /> } />
5462 < Route path = "*" component = { ( ) => < PageError code = { 404 } /> } />
5563 </ Route >
56- )
64+ )
0 commit comments