import { defineStore } from 'pinia';

export const userInfoStore = defineStore('userInfo', {
  state: () => ({
    userInfo: { }
  }),
  actions: {
    setUserInfo(obj) {
      if (obj && obj.token && this.userInfo.token !== obj.token) {
        this.userInfo = obj;
        localStorage.setItem('userInfo', JSON.stringify(this.userInfo));
        localStorage.setItem('token', obj.token);
      }
    },
    clearUserInfo() {
      this.userInfo = {};
      localStorage.removeItem('userInfo'); 
      localStorage.removeItem('token');
    }
  }
});