This commit is contained in:
ari
2025-11-20 16:25:35 +07:00
parent 5166229d06
commit bbdaeee304
3 changed files with 54 additions and 21 deletions
+12
View File
@@ -14,6 +14,7 @@ const props = defineProps<Props>()
const emit = defineEmits<{
submit: [data: any]
sso: []
response: [state: string]
}>()
const { handleSubmit, defineField, errors, meta } = useForm({
@@ -45,6 +46,14 @@ const onSSO = (async () => {
}
});
const test = useRoute()
const responseSSO = test.hash
if (responseSSO != null && responseSSO != '') {
console.log("Getting Response SSO...")
await emit('response', responseSSO)
}
</script>
<template>
@@ -85,7 +94,10 @@ const onSSO = (async () => {
</form>
<a href="/auth/keycloak/login">Login with Keycloak</a>
<Button @click="onSSO" target="_blank">
Login SSO
</Button>
<span>success {{ responseSSO }}</span>
</template>
+29 -21
View File
@@ -60,29 +60,11 @@ async function onSSO() {
});
try {
await keycloak.init({ onLoad: 'login-required' }); // Or 'login-required'
const authenticatedResult = await keycloak.init({ onLoad: 'login-required' }); // Or 'login-required'
// seelah line ini aku mek paham logic e tapi faktane dunno
const nuxtApp = useNuxtApp()
nuxtApp.provide('keycloak', keycloak);
const result = await xfetch('/api/v1/authentication/login-fes', 'POST', {
data: keycloak,
})
if (result.success) {
const { data: rawdata, meta } = result.body
if (meta.status === 'verified') {
login(rawdata)
navigateTo('/')
}
} else {
if (result.errors) {
Object.entries(result.errors).forEach(
([field, errorInfo]: [string, any]) => (apiErrors.value[field] = errorInfo.message),
)
} else {
apiErrors.value.general = result.error?.message || result.message || 'Login failed'
}
}
} catch (error) {
console.error('Keycloak initialization failed:', error);
}
@@ -144,10 +126,36 @@ async function onSSO() {
// external: true
// })
}
async function onResponseSSO(authenticatedResult: string) {
console.log("=================== onto login fes!!! ===================")
console.log(authenticatedResult)
if (authenticatedResult) {
const result = await xfetch('/api/v1/authentication/login-fes', 'POST', {
data: authenticatedResult,
})
if (result.success) {
const { data: rawdata, meta } = result.body
if (meta.status === 'verified') {
login(rawdata)
navigateTo('/')
}
} else {
if (result.errors) {
Object.entries(result.errors).forEach(
([field, errorInfo]: [string, any]) => (apiErrors.value[field] = errorInfo.message),
)
} else {
apiErrors.value.general = result.error?.message || result.message || 'Login failed'
}
}
}
}
</script>
<template>
<AppAuthLogin :schema="loginSchema" :is-loading="isLoading" @submit="onSubmit" @sso="onSSO" />
<AppAuthLogin :schema="loginSchema" :is-loading="isLoading" @submit="onSubmit" @sso="onSSO" @response="onResponseSSO" />
</template>
<style scoped></style>
+13
View File
@@ -0,0 +1,13 @@
<script setup lang="ts">
definePageMeta({
layout: 'blank',
public: true,
})
const test = useRoute()
const temp = test.hash
</script>
<template>
<span>success {{ temp }}</span>
</template>