corrigir erro de criar conta

This commit is contained in:
Rodrigo Lopes dos Santos
2026-01-29 17:52:22 +00:00
parent e0acd9879c
commit 22356086bb
3 changed files with 15 additions and 16 deletions

View File

@@ -14,9 +14,9 @@ type State = {
};
type AppContextValue = State & {
login: (email: string, password: string) => boolean;
login: (email: string, password: string) => User | null;
logout: () => void;
register: (payload: Omit<User, 'id' | 'shopId'> & { shopName?: string }) => boolean;
register: (payload: Omit<User, 'id' | 'shopId'> & { shopName?: string }) => User | null;
addToCart: (item: CartItem) => void;
removeFromCart: (refId: string) => void;
clearCart: () => void;
@@ -74,16 +74,16 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
const found = state.users.find((u) => u.email === email && u.password === password);
if (found) {
setState((s) => ({ ...s, user: found }));
return true;
return found;
}
return false;
return null;
};
const logout = () => setState((s) => ({ ...s, user: undefined }));
const register: AppContextValue['register'] = ({ shopName, ...payload }) => {
const exists = state.users.some((u) => u.email === payload.email);
if (exists) return false;
if (exists) return null;
if (payload.role === 'barbearia') {
const shopId = nanoid();
@@ -103,7 +103,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
users: [...s.users, user],
shops: [...s.shops, shop],
}));
return true;
return user;
}
const user: User = { ...payload, id: nanoid(), role: 'cliente' };
@@ -112,7 +112,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
user,
users: [...s.users, user],
}));
return true;
return user;
};
const addToCart: AppContextValue['addToCart'] = (item) => {
@@ -320,4 +320,3 @@ export const useApp = () => {
return ctx;
};