Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
Logout popup not working. How can I make one in MSAL

I am working on a project and trying to find out how to make a logout button on my webpage. It is using Vue2 and my script looks like this right now.

import * as msal from "@azure/msal-browser";

const msalConfig = {
  auth: {
    clientId: "Blank for security", // THIS SHGULD BE COMING FROM AN ENVIRONMENT VARIABLE VIA vue-cli dotenv
    authority: "https://login.microsoftonline.com/common/",
    redirectUri: "http://localhost:8080/",
  },
};

const msalInstance = new msal.PublicClientApplication(msalConfig);
  export default {
    data: () => ({
      msalInstance,
      isLoggedIn: false,
      loginError: false,
      drawer: null,
    }),
    methods: {
    async login() {
      try {
        const loginResponse = await msalInstance.loginPopup({
          redirectUri: "http://localhost:8080/",
        });

        console.log(loginResponse.account.username);

        this.isLoggedIn = true;
      } catch (error) {
        console.error(error);
        this.isLoggedIn = false;
        this.loginError = error;
      }
    },
  },
  }

i've looked for information about making a logout, but mainly they are all login, and i searched here, and cant seem to find how to log them out.

this is all using msar-browser. It might be something simple but i'm not 100% sure, on how to use it.

Thanks for the help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The MSAL library for JavaScript enables client-side JavaScript applications to authenticate users using Azure Active Directory accounts (AAD), Microsoft personal accounts (MSA) and social identity providers like Facebook, Google, LinkedIn, Microsoft accounts through Azure AD B2C service.

Coming back to your problem, the logout process for MSAL takes two steps.

  1. Clear the MSAL cache.
  2. Clear the session on the identity server.

The PublicClientApplication object exposes APIs that perform these actions.

You can solve your problem by using logoutRedirect. Using logoutRedirect will clear local cache of user tokens then redirect the window to the server signout page as shown below.

const currentAccount = msalInstance.getAccountByHomeId(homeAccountId);
await msalInstance.logoutRedirect({
        account: currentAccount,
        postLogoutRedirectUri: "https:/***/loggedOutPage"
    });

I would suggest to read this Logging Out of MSAL document on GitHub to get more understanding on the same.

Also check the well defined example in this Vue.js User Authentication document for more information.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda