mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
Correcoes
This commit is contained in:
parent
014e71e3f1
commit
26888e9824
16
src/App.tsx
16
src/App.tsx
@ -9,6 +9,7 @@ import { StoryLibrary } from './components/library/StoryLibrary';
|
|||||||
import { AuthUser, SavedStory } from './types/auth';
|
import { AuthUser, SavedStory } from './types/auth';
|
||||||
import { User, Theme } from './types';
|
import { User, Theme } from './types';
|
||||||
import { AuthProvider } from './contexts/AuthContext'
|
import { AuthProvider } from './contexts/AuthContext'
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
type AppStep =
|
type AppStep =
|
||||||
| 'welcome'
|
| 'welcome'
|
||||||
@ -20,6 +21,7 @@ type AppStep =
|
|||||||
| 'library';
|
| 'library';
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
|
const navigate = useNavigate();
|
||||||
const [step, setStep] = useState<AppStep>('welcome');
|
const [step, setStep] = useState<AppStep>('welcome');
|
||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
const [authUser, setAuthUser] = useState<AuthUser | null>(null);
|
const [authUser, setAuthUser] = useState<AuthUser | null>(null);
|
||||||
@ -34,10 +36,15 @@ export function App() {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const handleLogin = (email: string, password: string) => {
|
const handleLogin = async (credentials: { email: string; password: string }) => {
|
||||||
// In production: Implement actual authentication
|
try {
|
||||||
setAuthUser({ id: '1', email, name: 'Usuário' });
|
// In production: Implement actual authentication
|
||||||
setStep('library');
|
setAuthUser({ id: '1', email: credentials.email, name: 'Usuário' });
|
||||||
|
// Redirecionar para o dashboard ao invés de library
|
||||||
|
navigate('/dashboard');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erro ao fazer login:', err);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRegistrationComplete = (userData: User) => {
|
const handleRegistrationComplete = (userData: User) => {
|
||||||
@ -78,6 +85,7 @@ export function App() {
|
|||||||
{step === 'login' && (
|
{step === 'login' && (
|
||||||
<div className="min-h-screen flex items-center justify-center p-6">
|
<div className="min-h-screen flex items-center justify-center p-6">
|
||||||
<LoginForm
|
<LoginForm
|
||||||
|
userType="school"
|
||||||
onLogin={handleLogin}
|
onLogin={handleLogin}
|
||||||
onRegisterClick={() => setStep('register')}
|
onRegisterClick={() => setStep('register')}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,17 +1,20 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { LogIn } from 'lucide-react';
|
import { LogIn } from 'lucide-react';
|
||||||
import { useAuth } from '../../hooks/useAuth';
|
import { useAuth } from '../../hooks/useAuth';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
interface LoginFormProps {
|
interface LoginFormProps {
|
||||||
userType: 'school' | 'teacher' | 'student';
|
userType: 'school' | 'teacher' | 'student';
|
||||||
onLogin?: (email: string, password: string) => void;
|
onLogin?: (credentials: { email: string; password: string }) => Promise<void>;
|
||||||
|
onRegisterClick?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LoginForm({ userType, onLogin }: LoginFormProps) {
|
export function LoginForm({ userType, onLogin, onRegisterClick }: LoginFormProps) {
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const { signIn } = useAuth();
|
const { signIn } = useAuth();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -20,7 +23,11 @@ export function LoginForm({ userType, onLogin }: LoginFormProps) {
|
|||||||
try {
|
try {
|
||||||
const { user } = await signIn(email, password);
|
const { user } = await signIn(email, password);
|
||||||
if (user) {
|
if (user) {
|
||||||
onLogin(email, password);
|
if (userType === 'school') {
|
||||||
|
navigate('/dashboard');
|
||||||
|
} else if (onLogin) {
|
||||||
|
await onLogin({ email, password });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('Erro ao fazer login. Verifique suas credenciais.');
|
setError('Erro ao fazer login. Verifique suas credenciais.');
|
||||||
@ -83,15 +90,17 @@ export function LoginForm({ userType, onLogin }: LoginFormProps) {
|
|||||||
Entrar
|
Entrar
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div className="text-center">
|
{onRegisterClick && (
|
||||||
<button
|
<div className="text-center">
|
||||||
type="button"
|
<button
|
||||||
onClick={onRegisterClick}
|
type="button"
|
||||||
className="text-purple-600 hover:text-purple-500"
|
onClick={onRegisterClick}
|
||||||
>
|
className="text-purple-600 hover:text-purple-500"
|
||||||
Criar uma nova conta
|
>
|
||||||
</button>
|
Criar uma nova conta
|
||||||
</div>
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,10 +1,20 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
import { supabase } from '../lib/supabase'
|
import { supabase } from '../lib/supabase'
|
||||||
import { User } from '@supabase/supabase-js'
|
import { User, Session } from '@supabase/supabase-js'
|
||||||
|
|
||||||
|
interface AuthContextType {
|
||||||
|
user: User | null;
|
||||||
|
loading: boolean;
|
||||||
|
error: string | null;
|
||||||
|
signIn: (email: string, password: string) => Promise<{ user: User; session: Session }>;
|
||||||
|
signUp: (email: string, password: string) => Promise<{ user: User; session: Session }>;
|
||||||
|
signOut: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
export function useAuth() {
|
export function useAuth() {
|
||||||
const [user, setUser] = useState<User | null>(null)
|
const [user, setUser] = useState<User | null>(null)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Verificar sessão atual
|
// Verificar sessão atual
|
||||||
@ -67,6 +77,7 @@ export function useAuth() {
|
|||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
loading,
|
loading,
|
||||||
|
error,
|
||||||
signIn,
|
signIn,
|
||||||
signUp,
|
signUp,
|
||||||
signOut
|
signOut
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user