mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
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:
parent
89c325cc7c
commit
dea81a5711
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user