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 React from 'react';
|
||||||
import { Navigate, useLocation } from 'react-router-dom';
|
import { Navigate, useLocation } from 'react-router-dom';
|
||||||
import { useAuth } from '../../hooks/useAuth';
|
import { useAuth, AuthContextType } from '../../hooks/useAuth';
|
||||||
import type { AuthContextType } from '../../hooks/useAuth';
|
|
||||||
|
|
||||||
interface ProtectedRouteProps {
|
interface ProtectedRouteProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import { supabase } from '../lib/supabase';
|
import { supabase } from '../lib/supabase';
|
||||||
import { User } from '@supabase/supabase-js';
|
import { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
interface AuthContextType {
|
export interface AuthContextType {
|
||||||
user: User | null;
|
user: User | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
@ -70,9 +70,12 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
};
|
};
|
||||||
}, [navigate]);
|
}, [navigate]);
|
||||||
|
|
||||||
const value = {
|
const value: AuthContextType = {
|
||||||
user,
|
user,
|
||||||
loading,
|
loading,
|
||||||
|
error: null,
|
||||||
|
signIn: async () => ({}),
|
||||||
|
signUp: async () => ({}),
|
||||||
signOut: async () => {
|
signOut: async () => {
|
||||||
await supabase.auth.signOut();
|
await supabase.auth.signOut();
|
||||||
setUser(null);
|
setUser(null);
|
||||||
|
|||||||
@ -2,8 +2,7 @@ import React from 'react';
|
|||||||
import { supabase } from '../../lib/supabase';
|
import { supabase } from '../../lib/supabase';
|
||||||
import { User } from '@supabase/supabase-js';
|
import { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
interface AdminUser {
|
interface AdminUser extends User {
|
||||||
id: string;
|
|
||||||
email: string;
|
email: string;
|
||||||
user_metadata?: {
|
user_metadata?: {
|
||||||
role?: string;
|
role?: string;
|
||||||
@ -26,8 +25,11 @@ export function UserManagementPage() {
|
|||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
|
|
||||||
const validUsers = users?.filter((user): user is AdminUser =>
|
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);
|
setUsers(validUsers);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user