fix: corrige tipagem do sistema de autenticação

- Exporta interface AuthContextType corretamente
- Atualiza tipagem do contexto de autenticação com User do Supabase
- Corrige interface AdminUser para estender User do Supabase
- Implementa type guard mais seguro para filtragem de usuários
- Adiciona implementações vazias para signIn e signUp no AuthContext
This commit is contained in:
Lucas Santana 2024-12-20 13:53:09 -03:00
parent 89c325cc7c
commit dea81a5711
3 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,6 @@
import React from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { useAuth } from '../../hooks/useAuth';
import type { AuthContextType } from '../../hooks/useAuth';
import { useAuth, AuthContextType } from '../../hooks/useAuth';
interface ProtectedRouteProps {
children: React.ReactNode;

View File

@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
import { supabase } from '../lib/supabase';
import { User } from '@supabase/supabase-js';
interface AuthContextType {
export interface AuthContextType {
user: User | null;
loading: boolean;
error: string | null;
@ -70,9 +70,12 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
};
}, [navigate]);
const value = {
const value: AuthContextType = {
user,
loading,
error: null,
signIn: async () => ({}),
signUp: async () => ({}),
signOut: async () => {
await supabase.auth.signOut();
setUser(null);

View File

@ -2,8 +2,7 @@ import React from 'react';
import { supabase } from '../../lib/supabase';
import { User } from '@supabase/supabase-js';
interface AdminUser {
id: string;
interface AdminUser extends User {
email: string;
user_metadata?: {
role?: string;
@ -26,8 +25,11 @@ export function UserManagementPage() {
if (error) throw error;
const validUsers = users?.filter((user): user is AdminUser =>
typeof user.email === 'string'
) || [];
typeof user.email === 'string' && user.email !== undefined
).map(user => ({
...user,
email: user.email!,
})) || [];
setUsers(validUsers);
} catch (err) {