fixing auth sso
This commit is contained in:
parent
ede985939a
commit
93cf472aae
3 changed files with 50 additions and 20 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import HomeView from '@/views/HomeView.vue'
|
import HomeView from '@/views/HomeView.vue'
|
||||||
import MapView from '@/views/MapView.vue'
|
import MapView from '@/views/MapView.vue'
|
||||||
import MianView from '@/views/MianView.vue'
|
import MainView from '@/views/MainView.vue'
|
||||||
|
|
||||||
import keycloak from '@/plugins/keycloak'
|
import keycloak from '@/plugins/keycloak'
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ const router = createRouter({
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
name: 'home',
|
||||||
component: MianView,
|
component: MainView,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
|
|
@ -45,14 +45,14 @@ const router = createRouter({
|
||||||
name: 'history',
|
name: 'history',
|
||||||
component: () => import('@/views/HistoryView.vue'),
|
component: () => import('@/views/HistoryView.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
Auth: true,
|
Auth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: '/camera',
|
path: '/auth',
|
||||||
// name: 'camera',
|
name: 'auth',
|
||||||
// component: () => import('@/views/SampleCamera.vue'),
|
component: () => import('@/views/auth.vue'),
|
||||||
// },
|
},
|
||||||
/**
|
/**
|
||||||
* 404 Not Found
|
* 404 Not Found
|
||||||
* ref: https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route
|
* ref: https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route
|
||||||
|
|
@ -75,18 +75,18 @@ router.beforeEach((to, from, next) => {
|
||||||
console.log('keycloak===>', keycloak)
|
console.log('keycloak===>', keycloak)
|
||||||
console.log('keycloak authenticated===>', keycloak.authenticated)
|
console.log('keycloak authenticated===>', keycloak.authenticated)
|
||||||
|
|
||||||
// if (keycloak.authenticated === undefined) {
|
if (keycloak.authenticated === undefined) {
|
||||||
// window.location.href = 'https://bma-sso.frappet.synology.me'
|
window.location.href = 'https://bma-sso.frappet.synology.me'
|
||||||
// } else {
|
// } else {
|
||||||
// // keycloak.updateToken(60);
|
// // keycloak.updateToken(60);
|
||||||
// // const role = keycloak.tokenParsed?.role
|
// // const role = keycloak.tokenParsed?.role
|
||||||
// // if (role.includes(to.meta.Role)) {
|
// // if (role.includes(to.meta.Role)) {
|
||||||
// next()
|
// next()
|
||||||
// // } else {
|
// // } else {
|
||||||
// // next({ path: '' })
|
// // next({ path: '' })
|
||||||
// // // next();
|
// // // next();
|
||||||
// // }
|
// // }
|
||||||
// }
|
}
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
src/views/auth.vue
Normal file
30
src/views/auth.vue
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
function setCookie(name: string, value: any, days: number) {
|
||||||
|
let expires = ''
|
||||||
|
if (days) {
|
||||||
|
const date = new Date()
|
||||||
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)
|
||||||
|
expires = '; expires=' + date.toUTCString()
|
||||||
|
}
|
||||||
|
document.cookie = name + '=' + (value || '') + expires + '; path=/'
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
console.log('query', route.query.token)
|
||||||
|
console.log('accessToken', route.query.accessToken)
|
||||||
|
|
||||||
|
setCookie('BMAHRIS_KEYCLOAK_IDENTITY', route.query.token, 1)
|
||||||
|
setCookie('BMAHRIS_KEYCLOAK_REFRESH', route.query.accessToken, 1)
|
||||||
|
|
||||||
|
window.location.href = '/'
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div></div>
|
||||||
|
</template>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue