Cannot implement pinia store in own keycloak plugin vue3

Viewed 42

an App in vue3 + vite + pinia + keycloak

in main.ts

app.use(pinia)
app.use(router)
app.use(auth)
app.use(vuetify)
app.mount("#app")

but in my keycloak after init I try to use pinia store

  **const userStore = useUserStore()**

  try {
    const authenticated = await keycloak.init(KCInitOptions)

    if (authenticated) {
      const tokenParsed: TokenParsed = JSON.parse(JSON.stringify(keycloak.tokenParsed))
      userStore.setUserAuthStatus(authenticated)
      const user: User = {
        id: tokenParsed.sub || "",
        name: tokenParsed.name || "",
        email: tokenParsed.email || "",
        access_token: keycloak.token || "",
        refresh_token: keycloak.refreshToken || "",
      }

      **userStore.setUser(user)**
    }
  } catch (e) {
    console.error(e)
  }

  return {
    install: (app: App) => {
      app.provide("Auth", Auth)
    },
  }
}

but this results in error

enter image description here

I followed on https://pinia.vuejs.org/core-concepts/outside-component-usage.html#single-page-applications and coud implement that on vue router but not inside keycloak

How enable pinia in own Plugin?

0 Answers
Related