remove keycloak change use cookie only
This commit is contained in:
parent
24374ab8f2
commit
92b85ce4ef
23 changed files with 236 additions and 189 deletions
|
|
@ -4,10 +4,11 @@ import config from "@/app.config";
|
|||
import { onMounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useQuasar } from "quasar";
|
||||
import keycloak, { kcLogout } from "@/plugins/keycloak";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import CustomComponent from "@/components/CustomDialog.vue";
|
||||
import avatar from "@/assets/avatar_user.jpg";
|
||||
import { tokenParsed, logout } from "@/plugins/auth";
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
|
|
@ -36,9 +37,8 @@ const link = ref<string>("");
|
|||
*/
|
||||
onMounted(async () => {
|
||||
await fetchTotolNotificate();
|
||||
if (keycloak.tokenParsed != null) {
|
||||
fullname.value = keycloak.tokenParsed.name;
|
||||
}
|
||||
const user = await tokenParsed();
|
||||
fullname.value = user?.name;
|
||||
});
|
||||
|
||||
async function checkUser() {
|
||||
|
|
@ -65,7 +65,7 @@ async function checkUser() {
|
|||
},
|
||||
}).onCancel(async () => {
|
||||
showLoader();
|
||||
await kcLogout();
|
||||
await logout();
|
||||
setTimeout(() => {
|
||||
hideLoader();
|
||||
}, 1000);
|
||||
|
|
@ -132,15 +132,15 @@ const fetchlistNotification = async (index: number, type: string) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* logout keycloak
|
||||
* logout
|
||||
* confirm ก่อนออกจากระบบ
|
||||
*/
|
||||
const doLogout = () => {
|
||||
dialogConfirm(
|
||||
$q,
|
||||
async () => {
|
||||
// authen with keycloak client
|
||||
kcLogout();
|
||||
// authen with client
|
||||
logout();
|
||||
},
|
||||
"ยืนยันการออกจากระบบ",
|
||||
"ต้องการออกจากระบบใช่หรือไม่"
|
||||
|
|
@ -456,14 +456,14 @@ function onInfo() {
|
|||
>
|
||||
</q-item>
|
||||
|
||||
<q-item clickable v-close-popup>
|
||||
<!-- <q-item clickable v-close-popup>
|
||||
<q-item-section avatar style="min-width: 30px">
|
||||
<q-icon color="orange-9" size="18px" name="mdi-lock-outline" />
|
||||
</q-item-section>
|
||||
<q-item-section
|
||||
><q-item-label>เปลี่ยนรหัสผ่าน</q-item-label></q-item-section
|
||||
>
|
||||
</q-item>
|
||||
</q-item> -->
|
||||
|
||||
<q-item clickable v-close-popup @click="doLogout">
|
||||
<q-item-section avatar style="min-width: 30px">
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { kcAuthen } from "@/plugins/keycloak";
|
||||
import { kcAuthen } from "@/plugins/auth";
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
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());
|
||||
const params = await {
|
||||
access_token: route.query.token,
|
||||
expires_in: route.query.expires ? route.query.expires : 36000,
|
||||
refresh_token: route.query.accessToken,
|
||||
};
|
||||
setAuthen(params);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<!-- authen with keycloak client -->
|
||||
<!-- authen with client -->
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import axios from "axios";
|
||||
import keycloak, { keycloakConfig, kcAuthen } from "@/plugins/keycloak";
|
||||
import { setAuthen, authenticated } from "@/plugins/auth";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useQuasar } from "quasar";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
import CustomComponent from "@/components/CustomDialog.vue";
|
||||
|
||||
const router = useRouter();
|
||||
const mixin = useCounterMixin();
|
||||
|
|
@ -18,39 +19,38 @@ const password = ref<string>("");
|
|||
async function onSubmit() {
|
||||
showLoader();
|
||||
const formdata = new URLSearchParams();
|
||||
formdata.append("client_id", keycloakConfig.clientId);
|
||||
formdata.append("client_secret", keycloakConfig.clientSecret);
|
||||
formdata.append("grant_type", "password");
|
||||
formdata.append(
|
||||
"requested_token_type",
|
||||
"urn:ietf:params:oauth:token-type:refresh_token"
|
||||
);
|
||||
formdata.append("username", username.value);
|
||||
formdata.append("password", password.value);
|
||||
|
||||
await axios
|
||||
.post(
|
||||
`${keycloakConfig.url}/realms/${keycloakConfig.realm}/protocol/openid-connect/token`,
|
||||
formdata,
|
||||
{
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
}
|
||||
)
|
||||
.post(`${import.meta.env.VITE_API_URI_CONFIG}/org/login`, formdata, {
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
})
|
||||
.then(async (res) => {
|
||||
kcAuthen(res.data.access_token, res.data.refresh_token);
|
||||
console.log("res", res.data.result);
|
||||
setAuthen(res.data.result);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err, "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง");
|
||||
$q.dialog({
|
||||
component: CustomComponent,
|
||||
componentProps: {
|
||||
title: `ข้อความแจ้งเตือน`,
|
||||
message: `${err.response.data.message}`,
|
||||
icon: "warning",
|
||||
color: "red",
|
||||
onlycancel: true,
|
||||
},
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
onMounted(() => {
|
||||
if (keycloak.authenticated) {
|
||||
console.log("authenticated", keycloak.authenticated);
|
||||
onMounted(async () => {
|
||||
const checkAuthen = await authenticated();
|
||||
if (checkAuthen) {
|
||||
router.push("/");
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue