import { defineStore } from 'pinia'

import Cookies from "js-cookie"

import { getUserInfo } from '@/services/user'

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      info:{}      
    }
  },
  getters: {
  },
  actions: {
    async init() {
      //檢查cookie是否為登入狀態，若是則取得資料
      if(Cookies.get('token')){
        let res = await getUserInfo()
        if(res.code === 200){
          this.info = res.data
        }
      }
    }
  }
})