update auth
This commit is contained in:
parent
23afdc4df9
commit
ff3fb68219
12 changed files with 222 additions and 308 deletions
|
|
@ -2,10 +2,10 @@
|
|||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import axios from 'axios'
|
||||
import keycloak, { kcAuthen, keycloakConfig } from '@/plugins/keycloak'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { useCounterMixin } from '@/stores/mixin'
|
||||
import { setAuthen, authenticated } from '@/plugins/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const mixin = useCounterMixin()
|
||||
|
|
@ -18,24 +18,17 @@ 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('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)
|
||||
setAuthen(res.data.result)
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err, 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง')
|
||||
|
|
@ -45,10 +38,9 @@ async function onSubmit() {
|
|||
})
|
||||
}
|
||||
|
||||
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