@innertia-solutions/innertia-nuxt 0.1.63 → 0.1.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineEventHandler, readBody, createError } from 'h3'
|
|
2
|
+
import { writeSession } from '../../../utils/session'
|
|
3
|
+
import { normalizeLoginResponse } from '../../../utils/login'
|
|
4
|
+
|
|
5
|
+
// Login de plataforma (identidad separada, sin contexto de tenant). Llama a
|
|
6
|
+
// Laravel /platform/auth/login server-to-server; en éxito sella el JWT en la
|
|
7
|
+
// sesión httpOnly (igual que /_auth/login) y devuelve el body SIN token. Es
|
|
8
|
+
// imprescindible que pase por acá y no por el BFF catch-all /api/**, que solo
|
|
9
|
+
// proxea y NO sella la cookie → la sesión nunca quedaría establecida.
|
|
10
|
+
export default defineEventHandler(async (event) => {
|
|
11
|
+
const { email, password } = await readBody(event)
|
|
12
|
+
const config = useRuntimeConfig(event)
|
|
13
|
+
let data: any
|
|
14
|
+
try {
|
|
15
|
+
data = await $fetch(`${config.apiInternalUrl}/platform/auth/login`, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
body: { email, password },
|
|
18
|
+
headers: { Accept: 'application/json' },
|
|
19
|
+
})
|
|
20
|
+
} catch (err: any) {
|
|
21
|
+
const status = err?.response?.status ?? err?.statusCode ?? 500
|
|
22
|
+
throw createError({ statusCode: status, data: err?.data ?? null, statusMessage: 'login_failed' })
|
|
23
|
+
}
|
|
24
|
+
const { token, body } = normalizeLoginResponse(data)
|
|
25
|
+
await writeSession(event, { token })
|
|
26
|
+
return body
|
|
27
|
+
})
|