Closed joema-ww closed 1 month ago
Hi @joema-ww. Don't see the need to add code to support that, because you can use a watch on the keycloak reactive instance to setup the callbacks. Something like the following should work:
<script setup>
import { watch } from 'vue';
import { useKeycloak } from '@josempgon/vue-keycloak';
const { keycloak } = useKeycloak();
watch(
keycloak,
value => {
if (value) setKeycloakCallbacks(value);
},
{ immediate: true },
);
function setKeycloakCallbacks(kc) {
kc.onReady = authenticated => console.log('onReady:', authenticated);
kc.onAuthSuccess = () => console.log('onAuthSuccess');
kc.onAuthError = errorData => console.log('onAuthError:', errorData);
kc.onAuthRefreshSuccess = () => console.log('onAuthRefreshSuccess');
kc.onAuthRefreshError = () => console.log('onAuthRefreshError');
kc.onAuthLogout = () => console.log('onAuthLogout');
kc.onTokenExpired = () => console.log('onTokenExpired');
}
</script>
Great, everything is working as expected now! Thanks so much for sharing the solution. I'll close the issue.
keycloak-js
adapter supports setting callback listeners for certain events as documented here - https://www.keycloak.org/securing-apps/javascript-adapter#_callback_events.