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

Redirect loop fix #864

Merged
merged 3 commits into from
Jul 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/services/jwtInterceptor.service.js
Original file line number Diff line number Diff line change
@@ -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
}

5 changes: 5 additions & 0 deletions app/services/jwtInterceptor.service.spec.js
Original file line number Diff line number Diff line change
@@ -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() {
2 changes: 1 addition & 1 deletion app/services/tcAuth.service.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ import { getCurrentUser, logout as doLogout } from './userv3.service.js'
}

function isAuthenticated() {
return !!getCurrentUser() && !!AuthTokenService.getV2Token() && !!AuthTokenService.getTCSSOToken()
return !!getCurrentUser()
}

}