Skip to content

Commit

Permalink
Add logging messages to debug staging
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-emilius committed Jul 23, 2024
1 parent 13e1355 commit 842d8d7
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ const AuthenticationProvider = (props: PropsWithChildren<IAuthenticationProvider
const refreshAccessToken = () => {
keycloak
.updateToken(60 * 5)
.then((isSuccess) => !isSuccess && setAuthenticationTokens(undefined))
.then((isSuccess) => {
console.log('setAuthenticationTokens 1')

if (!isSuccess) {
setAuthenticationTokens(undefined)
}
})
}

const storeTokens = () => {
Expand All @@ -58,12 +64,13 @@ const AuthenticationProvider = (props: PropsWithChildren<IAuthenticationProvider
if (decodedRefreshToken?.exp) {
console.log(
'refresh token expires in seconds',
decodedRefreshToken?.exp - Date.now() / 1000,
Math.floor(decodedRefreshToken?.exp - Date.now() / 1000),
)
}

// refresh if already expired
if (decodedRefreshToken?.exp && decodedRefreshToken.exp <= Date.now() / 1000) {
console.log('setAuthenticationTokens 2')
return setAuthenticationTokens(undefined)
} else if (decodedAccessToken?.exp && decodedAccessToken.exp <= Date.now() / 1000) {
return refreshAccessToken()
Expand All @@ -72,18 +79,21 @@ const AuthenticationProvider = (props: PropsWithChildren<IAuthenticationProvider
if (decodedRefreshToken?.exp) {
refreshTokenTimeout = setTimeout(
() => {
console.log('setAuthenticationTokens 3')
setAuthenticationTokens(undefined)
},
Math.max(decodedRefreshToken.exp * 1000 - Date.now(), 0),
)
}

if (accessToken && refreshToken) {
console.log('setAuthenticationTokens 4')
setAuthenticationTokens({
access_token: accessToken,
refresh_token: refreshToken,
})
} else {
console.log('setAuthenticationTokens 5')
setAuthenticationTokens(undefined)
}
}
Expand All @@ -93,15 +103,15 @@ const AuthenticationProvider = (props: PropsWithChildren<IAuthenticationProvider
keycloak.onTokenExpired = () => refreshAccessToken()
keycloak.onAuthRefreshSuccess = () => storeTokens()

console.log('Initializing keycloak...', storedTokens, keycloak)
console.log('Initializing keycloak...')

void keycloak
.init({
refreshToken: storedTokens?.refresh_token,
token: storedTokens?.access_token,
})
.then(() => {
console.log('Keycloak initialized', keycloak)
console.log('Keycloak initialized')

storeTokens()
triggerReadySignal()
Expand Down

0 comments on commit 842d8d7

Please sign in to comment.