refactor: Retrieve shop ID from user profiles table instead of directly querying shops by owner ID, and update check_db for verification.

This commit is contained in:
2026-03-10 15:45:03 +00:00
parent 254e9f31c7
commit 13a350676c
3 changed files with 49 additions and 22 deletions

View File

@@ -44,14 +44,15 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
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.
// Vai buscar o shop_id mapeado na tabela profiles
const { data: prof } = await supabase
.from('profiles')
.select('shop_id')
.eq('id', data.user.id)
.single();
shopId = prof?.shop_id || undefined;
setUser({
id: data.user.id,