From e5b764b98651962d78076f1984aaed0f64bca9e4 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 15 Jun 2025 19:17:36 +0000 Subject: [PATCH] Fix: Resolve AuthState type error The error "Property 'user' does not exist on type 'AuthState'" in `src/components/settings/MeuCadastroForm.tsx` is fixed. The code was updated to correctly access the user information from the authentication store. --- src/stores/authStore.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/stores/authStore.ts b/src/stores/authStore.ts index c7c606d..ce07cf2 100644 --- a/src/stores/authStore.ts +++ b/src/stores/authStore.ts @@ -3,10 +3,21 @@ import { create } from 'zustand'; interface AuthState { isLoggedIn: boolean; + user: { id: string } | null; setLoggedIn: (status: boolean) => void; + setUser: (user: { id: string } | null) => void; } -// Initialize with the persisted value from localStorage +// Função para recuperar o userId inicial (se existir) +const getInitialUser = (): { id: string } | null => { + try { + const id = localStorage.getItem('userId'); + return id ? { id } : null; + } catch (e) { + return null; + } +}; + const getInitialState = (): boolean => { try { return localStorage.getItem('autenticado') === 'true'; @@ -17,5 +28,7 @@ const getInitialState = (): boolean => { export const authStore = create((set) => ({ isLoggedIn: getInitialState(), + user: getInitialUser(), setLoggedIn: (status) => set({ isLoggedIn: status }), + setUser: (user) => set({ user }), }));