Giter Site home page Giter Site logo

Comments (5)

Karkisushant avatar Karkisushant commented on June 3, 2024 2

@MarcelCode import { createApp } from "vue";

import App from "./App.vue";
import router from "./router";
import VueKeyCloak from '@dsb-norge/vue-keycloak-js'
import type { KeycloakInstance } from "keycloak-js";
const app = createApp(App)
    .use(VueKeyCloak, {
        config: {
            realm: "dss",
            url: import.meta.env.VITE_KEYCLOAK_BASE_URL,
            clientId: "dss-frontend",
        },
        init: {
            onLoad: 'check-sso',
            silentCheckSsoRedirectUri: window.location.origin + "/silent-check-sso.html",
            checkLoginIframe: false,
            silentCheckSsoFallback: false,
            redirectUri: import.meta.env.VITE_APP_BASE_URL + '/console',
            token:token,
            refreshToken:refreshToken
        },
        onReady(keycloak: KeycloakInstance) {
            if (keycloak.authenticated) {
                console.log('Authenticatied')
            } 

            router.beforeEach((to, from, next) => {
                if (to.matched.some(record => record.meta.requiresAuth)) {
                    if (keycloak.authenticated) {
                        return next();
                    } else {
                        let loginUrl = keycloak.createLoginUrl();
                        window.location.replace(loginUrl)
                    }
                } else {
                    return next();
                }
            })

            app.use(router)
                .use(vuetify)
            app.mount("#app");
        }
    })

`

One way I was able to make it work was by using the router navigation guard this way

from vue-keycloak-js.

Karkisushant avatar Karkisushant commented on June 3, 2024

@djdemarco Did you found any solutions to this issue ?

from vue-keycloak-js.

MarcelCode avatar MarcelCode commented on June 3, 2024

It would be really great if someone can give an example how to use it with the router in vue3

from vue-keycloak-js.

flangam avatar flangam commented on June 3, 2024

@Karkisushant

@djdemarco Did you found any solutions to this issue ?

I moved on to using another library since we will be using Nuxt 3 for the framework. Also, in the future we might switch to another authentication provider other than Keycloak so it's best to use a library that can cater to a wide range of identity providers. I'm using this now instead: https://github.com/sidebase/nuxt-auth

Nuxt 3's support of its native auth module is still in the planning stages as stated here: https://github.com/sidebase/nuxt-auth. Hence the need to use another library for authentication.

from vue-keycloak-js.

flangam avatar flangam commented on June 3, 2024

I moved on to using another authentication library instead

from vue-keycloak-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.