23 lines
No EOL
555 B
TypeScript
23 lines
No EOL
555 B
TypeScript
export default defineEventHandler(async (event) => {
|
|
const config = useRuntimeConfig(event)
|
|
const body = await readBody(event)
|
|
|
|
if (!body?.token) {
|
|
return { active: false }
|
|
}
|
|
|
|
const userinfoUrl = `${config.public.keycloakUrl}/realms/${config.public.keycloakRealm}/protocol/openid-connect/userinfo`
|
|
|
|
try {
|
|
const user = await $fetch(userinfoUrl, {
|
|
method: 'GET',
|
|
headers: {
|
|
Authorization: `Bearer ${body.token}`
|
|
}
|
|
})
|
|
|
|
return { active: true, user }
|
|
} catch (error) {
|
|
return { active: false }
|
|
}
|
|
}) |