msal working

This commit is contained in:
andrea.terzani
2025-04-16 19:31:21 +02:00
parent 5cc54c9332
commit 0e69938d97
6 changed files with 130 additions and 130 deletions

View File

@@ -0,0 +1,56 @@
<script setup>
import { useAuth } from '@websanova/vue-auth/src/v3.js';
import axios from 'axios';
import { onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { msalInstance } from './MsalConfig'; // wherever you created your MSAL instance
const router = useRouter()
const auth = useAuth();
onMounted(async () => {
console.log("Mounted on callback")
await msalInstance.initialize()
console.log("After initialize on callback")
const response = await msalInstance.handleRedirectPromise()
console.log("Response:",response)
if (response) {
// Do something with the response, e.g. save the user
localStorage.setItem('msalUser', JSON.stringify(response.account))
axios.post("/msauth/exchange",{}, {
headers: { Authorization: `Bearer ${response.accessToken}` }
}).then(res=>{
if(res.data.token){
auth.token(null,res.data.token,false);
auth.fetch().then(response=>{
console.log("1 user :" , response.data.data);
if (!response.data.data.selectedProject) {
router.push({ name: 'projects-list' });
} else {
router.push({ name: 'scenario-list' });
}
})
}else{
console.error("No token exchange with backend")
}
});
}
})
</script>
<template>
<div>Redirecting...</div>
</template>