Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 67ce538

Browse files
author
vikasrohit
authored
Merge pull request #864 from appirio-tech/feature/redirect-loop
Redirect loop fix
2 parents ebe35aa + 5b062e8 commit 67ce538

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

app/services/jwtInterceptor.service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { isTokenExpired, getFreshToken } from 'tc-accounts'
2727
.catch(function(err) {
2828
// Server will not or cannot refresh token
2929
logger.debug('Unable to refresh V3 token, redirecting to login')
30-
var retUrl = CONSTANTS.MAIN_URL + '/?next=' + config.url
31-
$window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(retUrl)
30+
var next = $state.href('dashboard', {}, {absolute: true})
31+
$window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(next)
3232

3333
return null
3434
})
@@ -83,8 +83,8 @@ import { isTokenExpired, getFreshToken } from 'tc-accounts'
8383
// logger.debug('idToken: ' + idToken)
8484
if (!TcAuthService.isAuthenticated() || idToken == null) {
8585
// logger.debug('redirecting to accounts app')
86-
var retUrl = CONSTANTS.MAIN_URL + '/?next=' + config.url
87-
$window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(retUrl)
86+
var next = $state.href('dashboard', {}, {absolute: true})
87+
$window.location = CONSTANTS.ACCOUNTS_APP_URL + '?retUrl=' + encodeURIComponent(next)
8888
return
8989
}
9090

app/services/jwtInterceptor.service.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ describe('JWT Interceptor Service', function() {
2727
fakeState = {
2828
go: sinon.spy(function(param) {
2929
return
30+
}),
31+
href: sinon.spy(function(stateName, toParams, params) {
32+
return 'https://topcoder.com/' + stateName
3033
})
3134
},
3235
fakeWindow = {
@@ -84,6 +87,7 @@ describe('JWT Interceptor Service', function() {
8487
expect($window.location).not.null
8588
expect($window.location).to.have.string(CONSTANTS.ACCOUNTS_APP_URL)
8689
expect(TcAuthService.isAuthenticated).to.be.have.been.calledOnce
90+
expect(fakeState.href).to.be.calledWith('dashboard')
8791
})
8892

8993
it('should redirect to login page for other endpoints', function() {
@@ -95,6 +99,7 @@ describe('JWT Interceptor Service', function() {
9599
expect($window.location).not.null
96100
expect($window.location).to.have.string(CONSTANTS.ACCOUNTS_APP_URL)
97101
expect(TcAuthService.isAuthenticated).to.be.have.been.calledOnce
102+
expect(fakeState.href).to.be.calledWith('dashboard')
98103
})
99104

100105
afterEach(function() {

app/services/tcAuth.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { getCurrentUser, logout as doLogout } from './userv3.service.js'
2525
}
2626

2727
function isAuthenticated() {
28-
return !!getCurrentUser() && !!AuthTokenService.getV2Token() && !!AuthTokenService.getTCSSOToken()
28+
return !!getCurrentUser()
2929
}
3030

3131
}

0 commit comments

Comments
 (0)