fix on all auth

This commit is contained in:
andrea.terzani
2025-04-17 15:47:57 +02:00
parent c2973ddb5e
commit f3d3f95cdc
2 changed files with 91 additions and 28 deletions

View File

@@ -1,12 +1,13 @@
<script setup>
import { useAuth } from '@websanova/vue-auth/src/v3.js';
import axios from 'axios';
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { msalInstance } from './MsalConfig'; // wherever you created your MSAL instance
const router = useRouter()
const auth = useAuth();
const message = ref('')
onMounted(async () => {
console.log("Mounted on callback")
@@ -19,7 +20,7 @@ onMounted(async () => {
console.log("Response:",response)
if (response) {
// Do something with the response, e.g. save the user
message.value ="Logging in to the application..."
localStorage.setItem('msalUser', JSON.stringify(response.account))
axios.post("/msauth/exchange",{}, {
headers: { Authorization: `Bearer ${response.accessToken}` }
@@ -35,12 +36,20 @@ onMounted(async () => {
router.push({ name: 'scenario-list' });
}
})
}).catch(res=>{
console.log("Error on token exchange:",res)
message.value = "Error authenticating on the application. Did you ask for authorization?"
visible.value = true;
});
}else{
message.value = "Error authenticating on the application. Did you ask for authorization?"
console.error("No token exchange with backend")
}
}).catch(res=>{
message.value = "Error authenticating on the application. Did you ask for authorization?"
});
@@ -52,5 +61,5 @@ onMounted(async () => {
</script>
<template>
<div>Redirecting...</div>
<div>{{message}}</div>
</template>