msal working
This commit is contained in:
56
src/views/pages/auth/Callback.vue
Normal file
56
src/views/pages/auth/Callback.vue
Normal 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>
|
||||
Reference in New Issue
Block a user