import type { User } from './user.d'

const sessionUser = localStorage.getItem('userInfo')
export const user = ref<User | null>(sessionUser ? JSON.parse(sessionUser) : null)

watch(
  () => user.value,
  (val) => {
    if (val)
      localStorage.setItem('userInfo', JSON.stringify(val))
    else
      localStorage.removeItem('userInfo')
  },
)