-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tryKeepExistingSessionAsync and loginCallbackAsync refresh loop in Vue #1426
Comments
Hi @RonanRobineau , do you have a full sample of code? I can try to build a vie implementation if you need it. |
Hi @guillaume-chervet ,
Making this creates the hard reload. <script setup>
import {OidcClient} from '@axa-fr/oidc-client'
import { ref } from 'vue';
const configuration = {
client_id: 'xxxxx',
redirect_uri: window.location.origin + '/oidc/callback',
silent_redirect_uri: window.location.origin + '/oidc/silent-callback',
scope: 'openid',
authority: 'xxxxx',
refresh_time_before_tokens_expiration_in_second: 40,
service_worker_relative_url: '/OidcServiceWorker.js',
service_worker_only: true,
};
const href = window.location.href;
const token = ref(null)
const vanillaOidc = OidcClient.getOrCreate(() => fetch)(configuration);
vanillaOidc.tryKeepExistingSessionAsync().then(() => {
token.value = vanillaOidc.tokens;
if (token.value) {
window.document.getElementById('logout').addEventListener('click', logout);
} else {
window.document.getElementById('login').addEventListener('click', login);
}
if (Math.floor((vanillaOidc.tokens.expiresAt - Date.now() / 1000) * 1000) < 0) {
login()
}
});
function logout() {
vanillaOidc.logoutAsync();
}
function login() {
vanillaOidc.loginAsync('/');
}
if (href.includes(configuration.redirect_uri)) {
vanillaOidc.loginCallbackAsync().then(() => document.location = localStorage.getItem('lastUrl'))
}
</script>
<template>
<slot />
</template> This is quite a simple one, I took the wrapper idea from the react-oidc and applied the vanillajs behaviour, but it does the job (except that you have to create 2 button with Update : adding the |
Issue and Steps to Reproduce
On my Vue app, using the vanilla oidc client, I have a loop of refresh when I try to use the
loginCallbackAsync
or use thetryKeepExistingSessionAsync
.Here is the flow: I got a Pinia store, and I instantialize the oidc client here (with getOrCreate), and 2 actions: login and callback.
Login works fine, but the
loginCallbackAsync
creates a reload of the page, without any eror (it is un an onMounted function).Same with
tryKeepExistingSessionAsync
, I have it on my root component, and it juste reload the page, again and again.I tried my configuration with the oidc-client-demo, and it works fine.
The text was updated successfully, but these errors were encountered: