feat: Implement shop ID association for 'barbearia' users and refine shop data queries.

This commit is contained in:
2026-03-10 14:51:19 +00:00
parent 77ca82bd39
commit 254e9f31c7
4 changed files with 45 additions and 4 deletions

View File

@@ -43,10 +43,21 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
// Pedido restrito à API de autenticação do Supabase
const { data } = await supabase.auth.getUser();
if (data.user) {
let shopId: string | undefined = undefined;
// tenta ir buscar a barbearia ligada ao user atual (owner_id)
const { data: existingShop } = await supabase
.from('shops')
.select('id')
.eq('owner_id', data.user.id)
.maybeSingle();
shopId = existingShop?.id; // Não forçamos igual a userid. Ou existe, ou é undefined.
setUser({
id: data.user.id,
email: data.user.email || '',
role: 'barbearia', // ajustar se tiveres roles
role: 'barbearia', // assumido estaticamente na V1, deve vir de profiles
shopId
} as User);
}
};