diff --git a/app/services/jwtInterceptor.service.js b/app/services/jwtInterceptor.service.js index ac734f750..3a9aa43a0 100644 --- a/app/services/jwtInterceptor.service.js +++ b/app/services/jwtInterceptor.service.js @@ -27,8 +27,8 @@ import { isTokenExpired, getFreshToken } from 'tc-accounts' .catch(function(err) { // Server will not or cannot refresh token logger.debug('Unable to refresh V3 token, redirecting to login') - var retUrl = CONSTANTS.MAIN_URL + '/?next=' + config.url - $window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(retUrl) + var next = $state.href('dashboard', {}, {absolute: true}) + $window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(next) return null }) @@ -83,8 +83,8 @@ import { isTokenExpired, getFreshToken } from 'tc-accounts' // logger.debug('idToken: ' + idToken) if (!TcAuthService.isAuthenticated() || idToken == null) { // logger.debug('redirecting to accounts app') - var retUrl = CONSTANTS.MAIN_URL + '/?next=' + config.url - $window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(retUrl) + var next = $state.href('dashboard', {}, {absolute: true}) + $window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(next) return } diff --git a/app/services/jwtInterceptor.service.spec.js b/app/services/jwtInterceptor.service.spec.js index 7dac6c7d3..e5a43d22a 100644 --- a/app/services/jwtInterceptor.service.spec.js +++ b/app/services/jwtInterceptor.service.spec.js @@ -27,6 +27,9 @@ describe('JWT Interceptor Service', function() { fakeState = { go: sinon.spy(function(param) { return + }), + href: sinon.spy(function(stateName, toParams, params) { + return 'https://topcoder.com/' + stateName }) }, fakeWindow = { @@ -84,6 +87,7 @@ describe('JWT Interceptor Service', function() { expect($window.location).not.null expect($window.location).to.have.string(CONSTANTS.ACCOUNTS_APP_URL) expect(TcAuthService.isAuthenticated).to.be.have.been.calledOnce + expect(fakeState.href).to.be.calledWith('dashboard') }) it('should redirect to login page for other endpoints', function() { @@ -95,6 +99,7 @@ describe('JWT Interceptor Service', function() { expect($window.location).not.null expect($window.location).to.have.string(CONSTANTS.ACCOUNTS_APP_URL) expect(TcAuthService.isAuthenticated).to.be.have.been.calledOnce + expect(fakeState.href).to.be.calledWith('dashboard') }) afterEach(function() { diff --git a/app/services/tcAuth.service.js b/app/services/tcAuth.service.js index 9aee1a3dc..306c951ef 100644 --- a/app/services/tcAuth.service.js +++ b/app/services/tcAuth.service.js @@ -25,7 +25,7 @@ import { getCurrentUser, logout as doLogout } from './userv3.service.js' } function isAuthenticated() { - return !!getCurrentUser() && !!AuthTokenService.getV2Token() && !!AuthTokenService.getTCSSOToken() + return !!getCurrentUser() } }