fix(auth): replace .maybeSingle() with .limit(1) to avoid 406 Not Acceptable errors on PostgREST for missing resources

This commit is contained in:
2026-08-19 20:43:38 +00:00
parent 1da0651a88
commit be5e86773b
3 changed files with 15 additions and 12 deletions
+4 -4
View File
@@ -46,14 +46,14 @@ export function UserInfo() {
useEffect(() => {
async function fetchUserProfile() {
if (!user) return;
const { data, error } = await supabase
const { data: profileArr, error } = await supabase
.from('profiles')
.select('full_name, email, profile_image_url')
.eq('id', user.id)
.maybeSingle();
.limit(1);
if (!error && data) {
setProfile(data);
if (!error && profileArr && profileArr.length > 0) {
setProfile(profileArr[0]);
} else {
setProfile({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
+4 -3
View File
@@ -209,16 +209,17 @@ export function useInterfaceResources() {
.from('profiles')
.select('privilege_id')
.eq('id', userId)
.maybeSingle();
.limit(1);
if (profileError) throw profileError;
if (!profile?.privilege_id) return [];
const priv = profile && profile.length > 0 ? profile[0].privilege_id : null;
if (!priv) return [];
const { data, error } = await supabase
.from('privilege_interface_resources')
.select('resource_key')
.eq('privilege_id', profile.privilege_id);
.eq('privilege_id', priv);
if (error) throw error;
+7 -5
View File
@@ -67,19 +67,20 @@ export function useUserResourcePermissions(resourceKey: string) {
// Enriquecer com dados do usuário
const enrichedData = await Promise.all(
(data || []).map(async (permission) => {
const { data: profileData } = await supabase
const { data: profileDataArr } = await supabase
.from('profiles')
.select('email, full_name')
.eq('id', permission.user_id)
.maybeSingle();
.limit(1);
const profileData = profileDataArr && profileDataArr.length > 0 ? profileDataArr[0] : null;
return {
user_id: permission.user_id,
resource_key: permission.resource_key,
permission_level: permission.permission as PermissionLevel,
created_at: permission.created_at,
updated_at: permission.updated_at,
profiles: profileData
profiles: profileData as any
} as UserInterfacePermission;
})
);
@@ -167,12 +168,13 @@ export function useUserResourcePermissions(resourceKey: string) {
}
// Verify user exists
const { data: userExists, error: userError } = await supabase
const { data: userExistsArr, error: userError } = await supabase
.from('profiles')
.select('id, email')
.eq('id', userId)
.maybeSingle();
.limit(1);
const userExists = userExistsArr && userExistsArr.length > 0 ? userExistsArr[0] : null;
if (userError || !userExists) {
console.error('User not found:', { userId, userError });
toast.error('Usuário não encontrado');