mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
fix: corrige tipagem do contexto de autenticação
- Adiciona tipagem User do Supabase para o estado do usuário - Corrige interface AuthContextType com tipos corretos - Atualiza AdminUser para garantir email obrigatório - Adiciona type guard para filtrar usuários válidos - Exporta e importa tipos do AuthContext corretamente
This commit is contained in:
parent
7430ae15a8
commit
89c325cc7c
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Navigate, useLocation } from 'react-router-dom';
|
import { Navigate, useLocation } from 'react-router-dom';
|
||||||
import { useAuth } from '../../hooks/useAuth';
|
import { useAuth } from '../../hooks/useAuth';
|
||||||
|
import type { AuthContextType } from '../../hooks/useAuth';
|
||||||
|
|
||||||
interface ProtectedRouteProps {
|
interface ProtectedRouteProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { LogOut, Settings, LayoutDashboard } from 'lucide-react';
|
import { LogOut, Settings, LayoutDashboard } from 'lucide-react';
|
||||||
import { useAuth } from '../../hooks/useAuth';
|
import { useAuth } from '../../hooks/useAuth';
|
||||||
|
import type { AuthContextType } from '../../hooks/useAuth';
|
||||||
|
|
||||||
export function ProfileMenu() {
|
export function ProfileMenu() {
|
||||||
const { user, userRole, signOut } = useAuth();
|
const { user, userRole, signOut } = useAuth();
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { supabase } from '../lib/supabase';
|
import { supabase } from '../lib/supabase';
|
||||||
|
import { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
interface AuthContextType {
|
interface AuthContextType {
|
||||||
user: any;
|
user: User | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
signIn: (email: string, password: string) => Promise<any>;
|
signIn: (email: string, password: string) => Promise<any>;
|
||||||
@ -16,7 +17,7 @@ const AuthContext = React.createContext<AuthContextType | undefined>(undefined);
|
|||||||
|
|
||||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [user, setUser] = React.useState<any>(null);
|
const [user, setUser] = React.useState<User | null>(null);
|
||||||
const [userRole, setUserRole] = React.useState<string | null>(null);
|
const [userRole, setUserRole] = React.useState<string | null>(null);
|
||||||
const [loading, setLoading] = React.useState(true);
|
const [loading, setLoading] = React.useState(true);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { supabase } from '../../lib/supabase';
|
import { supabase } from '../../lib/supabase';
|
||||||
|
import { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
interface User {
|
interface AdminUser {
|
||||||
id: string;
|
id: string;
|
||||||
email: string;
|
email: string;
|
||||||
user_metadata?: {
|
user_metadata?: {
|
||||||
@ -10,7 +11,7 @@ interface User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function UserManagementPage() {
|
export function UserManagementPage() {
|
||||||
const [users, setUsers] = React.useState<User[]>([]);
|
const [users, setUsers] = React.useState<AdminUser[]>([]);
|
||||||
const [loading, setLoading] = React.useState(true);
|
const [loading, setLoading] = React.useState(true);
|
||||||
const [error, setError] = React.useState<string | null>(null);
|
const [error, setError] = React.useState<string | null>(null);
|
||||||
const [updating, setUpdating] = React.useState<string | null>(null);
|
const [updating, setUpdating] = React.useState<string | null>(null);
|
||||||
@ -23,7 +24,12 @@ export function UserManagementPage() {
|
|||||||
try {
|
try {
|
||||||
const { data: { users }, error } = await supabase.auth.admin.listUsers();
|
const { data: { users }, error } = await supabase.auth.admin.listUsers();
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
setUsers(users?.filter(user => user.email) || []);
|
|
||||||
|
const validUsers = users?.filter((user): user is AdminUser =>
|
||||||
|
typeof user.email === 'string'
|
||||||
|
) || [];
|
||||||
|
|
||||||
|
setUsers(validUsers);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erro ao buscar usuários:', err);
|
console.error('Erro ao buscar usuários:', err);
|
||||||
setError('Não foi possível carregar os usuários');
|
setError('Não foi possível carregar os usuários');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user