Fix useAuthentik composable for SSR
All checks were successful
build-and-deploy / build (push) Successful in 44s
build-and-deploy / deploy (push) Successful in 2s

- Use useState to pass server headers to client
- Fix 'useAuthentik is not defined' error
- Ensure headers are read only on server side
This commit is contained in:
2025-10-12 22:56:21 -06:00
parent 7de670d824
commit 65304fcade

View File

@@ -3,9 +3,12 @@
* Los headers son inyectados por Authentik Proxy Outpost * Los headers son inyectados por Authentik Proxy Outpost
*/ */
export const useAuthentik = () => { export const useAuthentik = () => {
// Leer headers en el servidor y almacenarlos en state
const authentikUser = useState('authentikUser', () => {
// Solo en el servidor, leer los headers
if (process.server) {
const headers = useRequestHeaders() const headers = useRequestHeaders()
const user = computed(() => {
const username = headers['x-authentik-username'] const username = headers['x-authentik-username']
const email = headers['x-authentik-email'] const email = headers['x-authentik-email']
const name = headers['x-authentik-name'] const name = headers['x-authentik-name']
@@ -26,8 +29,12 @@ export const useAuthentik = () => {
// Generar avatar URL usando UI Avatars // Generar avatar URL usando UI Avatars
avatar: `https://ui-avatars.com/api/?name=${encodeURIComponent(name || username)}&background=random&size=128` avatar: `https://ui-avatars.com/api/?name=${encodeURIComponent(name || username)}&background=random&size=128`
} }
}
return null
}) })
const user = computed(() => authentikUser.value)
const isAuthenticated = computed(() => !!user.value) const isAuthenticated = computed(() => !!user.value)
const logout = () => { const logout = () => {