31 lines
706 B
JavaScript
31 lines
706 B
JavaScript
import { defineStore } from 'pinia';
|
|
import { ref, watch } from 'vue';
|
|
|
|
export const useUserStore = defineStore('user', () => {
|
|
const userInfo = ref(null);
|
|
|
|
watch(userInfo, (newValue) => {
|
|
if (newValue) {
|
|
localStorage.setItem('userInfo', JSON.stringify(newValue));
|
|
} else {
|
|
localStorage.removeItem('userInfo');
|
|
}
|
|
});
|
|
|
|
function setUserInfo(newUserInfo) {
|
|
console.log("Setting new user info");
|
|
userInfo.value = newUserInfo;
|
|
}
|
|
|
|
function clearUserInfo() {
|
|
console.log("Clearing user info");
|
|
userInfo.value = null;
|
|
}
|
|
|
|
return {
|
|
userInfo,
|
|
setUserInfo,
|
|
clearUserInfo,
|
|
};
|
|
})
|