Fix useAuthentik composable for SSR
- 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:
@@ -3,9 +3,12 @@
|
||||
* Los headers son inyectados por Authentik Proxy Outpost
|
||||
*/
|
||||
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 user = computed(() => {
|
||||
const username = headers['x-authentik-username']
|
||||
const email = headers['x-authentik-email']
|
||||
const name = headers['x-authentik-name']
|
||||
@@ -26,8 +29,12 @@ export const useAuthentik = () => {
|
||||
// Generar avatar URL usando UI Avatars
|
||||
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 logout = () => {
|
||||
|
||||
Reference in New Issue
Block a user