import { defineStore } from 'pinia' import { ResponseStatus } from '@/helpers' import { self as api, users as userApi } from '@/services/api' export const useSessionStore = defineStore({ id: 'session', state: () => ({ connectionState: false, currentUser: null, isAuthenticated: false, self: null, }), getters: { getUser: (state) => state.currentUser }, actions: { async fetchSelf() { try { const response = await api.findOne() if (response.status === ResponseStatus.Success) { this.self = response.data return { success: true, message: response.code } } return { success: false, message: response.code } } catch (error) { return { success: false } } }, setConnectionState(connectionState) { this.connectionState = connectionState }, setUser(user, success) { this.currentUser = user this.isAuthenticated = success }, async updateSharing(id, data) { try { const response = await userApi.updateSharing(id, data) if (response.status === ResponseStatus.Success) { return { success: true, message: response.code } } return { success: false, message: response.code } } catch (error) { return { success: false } } } } })