- Add missing import for oauthAuthentikEventHandler - Remove default placeholder URLs in nuxt.config.ts - Fixes 404 error on /auth/authentik endpoint
36 lines
924 B
TypeScript
36 lines
924 B
TypeScript
import { oauthAuthentikEventHandler } from '../../utils/oauth-authentik'
|
|
|
|
/**
|
|
* OAuth Authentik Login Handler
|
|
* Ruta: /auth/authentik
|
|
*
|
|
* Este endpoint inicia el flujo OAuth con Authentik
|
|
*/
|
|
export default oauthAuthentikEventHandler({
|
|
config: {
|
|
emailRequired: true
|
|
},
|
|
async onSuccess(event, { user, tokens }) {
|
|
// Guardar información del usuario en la sesión
|
|
await setUserSession(event, {
|
|
user: {
|
|
id: user.id,
|
|
email: user.email,
|
|
name: user.name || user.preferred_username,
|
|
username: user.preferred_username,
|
|
picture: user.picture,
|
|
groups: user.groups || []
|
|
},
|
|
loggedInAt: Date.now()
|
|
})
|
|
|
|
// Redirigir al dashboard después del login
|
|
return sendRedirect(event, '/')
|
|
},
|
|
|
|
async onError(event, error) {
|
|
console.error('Authentik OAuth error:', error)
|
|
return sendRedirect(event, '/error?message=auth_failed')
|
|
}
|
|
})
|