fixing check token
This commit is contained in:
parent
56aa900ea3
commit
1a8a380f24
7 changed files with 112 additions and 77 deletions
27
src/views/Error404NotFound.vue
Normal file
27
src/views/Error404NotFound.vue
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<script lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "Error404NotFound",
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="fullscreen bg-blue-10 text-white text-center q-pa-md flex flex-center"
|
||||
>
|
||||
<div>
|
||||
<div class="text-h1">ไม่พบหน้าที่ต้องการ</div>
|
||||
<div class="text-h2">(404 Page Not Found)</div>
|
||||
<q-btn
|
||||
class="q-mt-xl"
|
||||
color="white"
|
||||
text-color="blue"
|
||||
unelevated
|
||||
to="/"
|
||||
label="กลับไปหน้าหลัก"
|
||||
no-caps
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -1,28 +1,27 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { kcAuthen } from "@/plugins/keycloak";
|
||||
|
||||
const route = useRoute()
|
||||
const route = useRoute();
|
||||
|
||||
function setCookie(name: string, value: any, days: number) {
|
||||
let expires = ''
|
||||
let expires = "";
|
||||
if (days) {
|
||||
const date = new Date()
|
||||
date.setTime(date.getTime() + days * 24 * 60 * 55 * 1000)
|
||||
expires = '; expires=' + date.toUTCString()
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + days * 24 * 60 * 55 * 1000);
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + '=' + (value || '') + expires + '; path=/'
|
||||
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 = '/'
|
||||
})
|
||||
onMounted(() => {
|
||||
if (route.query.token && route.query.accessToken) {
|
||||
// console.log('query', route.query.token)
|
||||
// console.log('accessToken', route.query.accessToken)
|
||||
kcAuthen(route.query.token.toString(), route.query.accessToken.toString());
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import axios from "axios";
|
||||
import keycloak, { keycloakConfig } from "@/plugins/keycloak";
|
||||
import keycloak, { keycloakConfig, kcAuthen } from "@/plugins/keycloak";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
|
@ -13,16 +13,6 @@ const $q = useQuasar(); //ใช้ noti quasar
|
|||
|
||||
const { showLoader, hideLoader, messageError } = mixin;
|
||||
|
||||
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=/";
|
||||
}
|
||||
|
||||
const username = ref<string>("");
|
||||
const password = ref<string>("");
|
||||
async function onSubmit() {
|
||||
|
|
@ -49,9 +39,7 @@ async function onSubmit() {
|
|||
}
|
||||
)
|
||||
.then(async (res) => {
|
||||
await setCookie("BMAHRIS_KEYCLOAK_IDENTITY", res.data.access_token, 1);
|
||||
await setCookie("BMAHRIS_KEYCLOAK_REFRESH", res.data.refresh_token, 1);
|
||||
window.location.href = "/";
|
||||
kcAuthen(res.data.access_token, res.data.refresh_token);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err, "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง");
|
||||
|
|
@ -59,19 +47,10 @@ async function onSubmit() {
|
|||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
|
||||
// if (response.status !== 200) {
|
||||
// messageError($q, err)
|
||||
// } else {
|
||||
// await setCookie('BMAHRIS_KEYCLOAK_IDENTITY', response.data.access_token, 1)
|
||||
// await setCookie('BMAHRIS_KEYCLOAK_REFRESH', response.data.refresh_token, 1)
|
||||
// router.push('/')
|
||||
// }
|
||||
}
|
||||
onMounted(() => {
|
||||
if (keycloak.authenticated) {
|
||||
console.log("authenticated", keycloak.authenticated);
|
||||
|
||||
router.push("/");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue