WIP - added front end auth

This commit is contained in:
Francisco Gaona
2025-12-21 09:38:51 +01:00
parent fbfaf7bb9f
commit 1d610f0d2b
22 changed files with 558 additions and 88 deletions

View File

@@ -0,0 +1,32 @@
export const useAuth = () => {
const tokenCookie = useCookie('token')
const isLoggedIn = () => {
if (!import.meta.client) return false
const token = localStorage.getItem('token')
const tenantId = localStorage.getItem('tenantId')
return !!(token && tenantId)
}
const logout = () => {
if (import.meta.client) {
localStorage.removeItem('token')
localStorage.removeItem('tenantId')
localStorage.removeItem('user')
}
// Clear cookie for server-side check
tokenCookie.value = null
}
const getUser = () => {
if (!import.meta.client) return null
const userStr = localStorage.getItem('user')
return userStr ? JSON.parse(userStr) : null
}
return {
isLoggedIn,
logout,
getUser,
}
}