fixing auth

This commit is contained in:
Warunee Tamkoo 2024-07-26 12:52:47 +07:00
parent f4592d2844
commit 3c4202a928
7 changed files with 91 additions and 102 deletions

View file

@ -3,7 +3,7 @@ import App from "./App.vue";
import router from "./router";
import { Dialog, Notify, Quasar, Loading } from "quasar";
import "./quasar-user-options";
import keycloak from "@/plugins/keycloak";
import keycloak, { getToken } from "@/plugins/keycloak";
import qDraggableTable from "quasar-ui-q-draggable-table";
import "quasar-ui-q-draggable-table/dist/index.css";
@ -83,28 +83,14 @@ app.component(
app.config.globalProperties.$http = http;
// authen with keycloak client
function getCookie(name: string) {
const nameEQ = name + "=";
const ca = document.cookie.split(";");
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == " ") c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
const auth = await getToken();
const kcToken = getCookie("BMAHRIS_KEYCLOAK_IDENTITY");
const kcRefreshToken = getCookie("BMAHRIS_KEYCLOAK_REFRESH");
if (kcToken && kcRefreshToken) {
if (auth.token && auth.refresh_token) {
keycloak.init({
// onLoad: 'login-required',
checkLoginIframe: false,
token: kcToken,
refreshToken: kcRefreshToken,
token: auth.token,
refreshToken: auth.refresh_token,
});
// .then((authenticated) => {
// console.log("authenticated", authenticated);
// if (!authenticated) {