From 87121d00fdeb196a63df1c505a3acc9bea10726a Mon Sep 17 00:00:00 2001 From: ari Date: Fri, 21 Nov 2025 15:57:09 +0700 Subject: [PATCH] update merge dan set cookies --- app/composables/useKeycloack.ts | 8 ++++---- server/api/v1/authentication/login-fes.post.ts | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/composables/useKeycloack.ts b/app/composables/useKeycloack.ts index 563b3d1a..09f72a8c 100644 --- a/app/composables/useKeycloack.ts +++ b/app/composables/useKeycloack.ts @@ -72,10 +72,10 @@ export function useKeycloak() { const getProfile = () => profile.value; // init on client automatically - // onBeforeMount(() => { - // // try check-sso silently - // if (!initialized.value) initKeycloak("check-sso"); - // }); + onBeforeMount(() => { + // try check-sso silently + if (!initialized.value) initKeycloak("check-sso"); + }); const apiErrors = ref>({}) const { login } = useUserStore() diff --git a/server/api/v1/authentication/login-fes.post.ts b/server/api/v1/authentication/login-fes.post.ts index 64d54a71..bae714de 100644 --- a/server/api/v1/authentication/login-fes.post.ts +++ b/server/api/v1/authentication/login-fes.post.ts @@ -2,7 +2,6 @@ import { getRequestURL, readBody, setCookie } from 'h3' // Function to verify JWT token with the userinfo endpoint export default defineEventHandler(async (event) => { - console.log("=================== MASUK FE SSO! ===================") const body = await readBody(event) const url = getRequestURL(event) const config = useRuntimeConfig() @@ -40,6 +39,22 @@ export default defineEventHandler(async (event) => { }, }) + if (resp.status === 200) { + const data = await resp.json() + + if (data?.data?.accessToken) { + setCookie(event, 'authentication', data.data.accessToken, { + path: '/', + httpOnly: true, + sameSite: 'strict', + maxAge: 60 * 60 * 24, + }) + + delete data.data.accessToken + return data + } + } + return new Response(await resp.text(), { status: resp.status, headers: {