@@ -86,12 +86,12 @@ export default {
86
86
renewToken ( instance , retries = 0 ) {
87
87
const maxRetries = 2
88
88
89
- instance . updateToken ( 1800 ) . success ( ( refreshed ) => {
89
+ instance . updateToken ( 1800 ) . then ( ( refreshed ) => {
90
90
if ( refreshed ) {
91
91
this . setLocalToken ( instance )
92
92
}
93
93
this . scheduleRenewal ( instance )
94
- } ) . error ( ( e ) => {
94
+ } ) . catch ( ( e ) => {
95
95
console . log ( e )
96
96
// The refresh token is expired or was rejected
97
97
// we will retry after 60 sec (up to the count defined by maxRetries)
@@ -113,52 +113,61 @@ export default {
113
113
return new Promise ( ( resolve , reject ) => {
114
114
this . getInstance ( )
115
115
. then ( ( instance ) => {
116
+ console . log ( "INSTANCE: " , instance )
116
117
if ( instance . authenticated && ApiService . hasAuthHeader ( ) && ! instance . isTokenExpired ( 0 ) ) {
117
118
// We've already authenticated, have a header, and we've not expired.
118
119
resolve ( instance )
119
120
} else {
121
+
122
+ this . removeLocalToken ( )
123
+ instance . clearToken ( )
124
+ // We update the store reference only after wiring up the API. (Someone might be waiting
125
+ // for login to complete before taking some action. )
126
+ store . commit ( 'SET_KEYCLOAK' , instance )
127
+ resolve ( instance )
120
128
// Attempt to retrieve a stored token, this may avoid us having to refresh the page.
121
- const token = localStorage . getItem ( 'token' )
122
- const refreshToken = localStorage . getItem ( 'refreshToken' )
123
- const idToken = localStorage . getItem ( 'idToken' )
124
- instance . init ( {
125
- pkceMethod : 'S256' ,
126
- onLoad : 'check-sso' ,
127
- checkLoginIframe : true ,
128
- timeSkew : 10 , // Allow for some deviation
129
- token,
130
- refreshToken,
131
- idToken }
132
- ) . success ( ( result ) => {
133
- if ( instance . authenticated ) {
134
- // We may have been authenticated, but the token could be expired.
135
- instance . updateToken ( 60 ) . success ( ( ) => {
136
- // Store the token to avoid future round trips, and wire up the API
137
- this . setLocalToken ( instance )
138
- // We update the store reference only after wiring up the API. (Someone might be waiting
139
- // for login to complete before taking some action. )
140
- // Assumes that store passed in includes a 'SET_KEYCLOAK' mutation!
141
- store . commit ( 'SET_KEYCLOAK' , instance )
142
- this . scheduleRenewal ( instance )
143
- resolve ( instance )
144
- } ) . error ( ( ) => {
145
- // The refresh token is expired or was rejected
146
- this . removeLocalToken ( )
147
- instance . clearToken ( )
148
- // We update the store reference only after wiring up the API. (Someone might be waiting
149
- // for login to complete before taking some action. )
150
- store . commit ( 'SET_KEYCLOAK' , instance )
151
- resolve ( instance )
152
- } )
153
- } else {
154
- // We may have failed to authenticate, for many reasons, e.g. - it may be we never logged in,
155
- // or have an expired token.
156
- store . commit ( 'SET_KEYCLOAK' , instance )
157
- resolve ( instance )
158
- }
159
- } ) . error ( ( e ) => {
160
- reject ( e )
161
- } )
129
+ // const token = localStorage.getItem('token')
130
+ // const refreshToken = localStorage.getItem('refreshToken')
131
+ // const idToken = localStorage.getItem('idToken')
132
+ // instance.init({
133
+ // pkceMethod: 'S256',
134
+ // onLoad: 'check-sso',
135
+ // checkLoginIframe: true,
136
+ // timeSkew: 10, // Allow for some deviation
137
+ // token,
138
+ // refreshToken,
139
+ // idToken,
140
+ // }
141
+ // ).then((result) => {
142
+ // if (instance.authenticated) {
143
+ // // We may have been authenticated, but the token could be expired.
144
+ // instance.updateToken(60).then(() => {
145
+ // // Store the token to avoid future round trips, and wire up the API
146
+ // this.setLocalToken(instance)
147
+ // // We update the store reference only after wiring up the API. (Someone might be waiting
148
+ // // for login to complete before taking some action. )
149
+ // // Assumes that store passed in includes a 'SET_KEYCLOAK' mutation!
150
+ // store.commit('SET_KEYCLOAK', instance)
151
+ // this.scheduleRenewal(instance)
152
+ // resolve(instance)
153
+ // }).error(() => {
154
+ // // The refresh token is expired or was rejected
155
+ // this.removeLocalToken()
156
+ // instance.clearToken()
157
+ // // We update the store reference only after wiring up the API. (Someone might be waiting
158
+ // // for login to complete before taking some action. )
159
+ // store.commit('SET_KEYCLOAK', instance)
160
+ // resolve(instance)
161
+ // })
162
+ // } else {
163
+ // // We may have failed to authenticate, for many reasons, e.g. - it may be we never logged in,
164
+ // // or have an expired token.
165
+ // store.commit('SET_KEYCLOAK', instance)
166
+ // resolve(instance)
167
+ // }
168
+ // }).then((e) => {
169
+ // reject(e)
170
+ // })
162
171
}
163
172
} )
164
173
. catch ( ( error ) => {
0 commit comments