feat: Implement shop ID association for 'barbearia' users and refine shop data queries.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user