question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Newbie question...component rendered before auth kicks in

See original GitHub issue

Hi there,

I’m new to Vue and I’m trying to plug this module in. I’m using the following code:

createApp(App)
    .use(VueKeycloakJs, {
        init: {
            onLoad: 'login-required',
        },
        config: {
            url: 'http://localhost:8080/auth',
            clientId: 'xxx',
            realm: 'xxx'
        },
        onReady (keycloak) {
            console.log('Keycloak ready', keycloak)
            keycloak.updateToken(60).then(() => {
                console.log("Token refreshed")
            })
        }
    })
    .use(router)
    .use(logger)
    .mount('#app');

In one of my components I have this bit of code:

const app = getCurrentInstance()
const props = app.appContext.config.globalProperties.$keycloak
log.info(`Hello`, props);

What I’m noticing is that log statement outputs before the auth kicks in resulting in all the properties being empty. It’s worth mentioning I’m using vite as well so whenever I try ‘Vue.propotype.$keycloak’ I get a different error.

I would expect the first middleware to kick in first and then subsequent ones. I mean this could be a user error issue so any help would be appreciated.

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
baltomcommented, Jun 14, 2021

It’s probably the easiest solution to the problem. But it also slows down the initial “time to draw” of your application. As in it will stay white until your keycloak responds and the plugin loads fully. Which may be no problem for you though

0reactions
baltomcommented, Jun 15, 2021

Yeah something like that. So you’ll be able to show to the end user that your app has started but is still “doing something”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Suspense for Data Fetching (Experimental) - React
We call this approach “fetch-on-render” because it doesn't start fetching until after the component has rendered on the screen. This leads to a...
Read more >
sudheerj/reactjs-interview-questions: List of top 500 ... - GitHub
Before React 16.3. componentWillMount: Executed before rendering and is used for App level configuration in your root component.
Read more >
Build a React.js Application with User Login and Authentication
With this, using the Authenticated component, when we have a user session we'll render a link to the /profile page and allow our...
Read more >
Protected Routes with React Function Components
Protected routes allow us to ensure only logged in users can access certain parts of our site that may contain private user information....
Read more >
Private route get Authentication before render Component
My problem is that current route will be redirect to login page while waiting authentication result. It will be return page if authenticated....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found