import { defineStore } from 'pinia'
import { ref } from 'vue'
import { IUser } from '@/types/user/user'

export const useAuthStore = defineStore(
	'user',
	() => {
		const user = ref<IUser>()

		function setUser(data: IUser) {
			user.value = data
		}

		function getUser() {
			return user.value
		}

		function clearUser() {
			user.value = void 0
		}

		return {
			user,
			setUser,
			getUser,
			clearUser
		}
	},
	{
		// 开启数据持久化
		persist: true
	}
)
