updateAuthen

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-07-25 12:57:27 +07:00
parent 8f103aeb71
commit 02827aa02d
5 changed files with 63 additions and 21 deletions

30
src/views/auth.vue Normal file
View file

@ -0,0 +1,30 @@
<script setup lang="ts">
import { onMounted } 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 * 55 * 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>

View file

@ -1,8 +1,8 @@
<!-- authen with keycloak client -->
<script setup lang="ts">
import { ref } from "vue";
import { ref, onMounted } from "vue";
import axios from "axios";
import { keycloakConfig } from "@/plugins/keycloak";
import keycloak, { keycloakConfig } from "@/plugins/keycloak";
import { useRouter } from "vue-router";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
@ -68,6 +68,13 @@ async function onSubmit() {
// router.push('/')
// }
}
onMounted(() => {
if (keycloak.authenticated) {
console.log("authenticated", keycloak.authenticated);
router.push("/");
}
});
</script>
<template>