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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user