Initial commit: Expedição Gold SaaS

This commit is contained in:
Carlos
2026-06-25 00:55:34 +02:00
commit 1bf21f0754
13 changed files with 1356 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
import '../styles/globals.css';
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
}
+31
View File
@@ -0,0 +1,31 @@
import { compareSync } from 'bcryptjs';
// In-memory store (same as signup)
let users = [];
export default function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' });
}
const { username, password } = req.body;
if (!username || !password) {
return res.status(400).json({ message: 'Username and password required' });
}
const user = users.find(u => u.username === username);
if (!user) {
return res.status(401).json({ message: 'Invalid credentials' });
}
const valid = compareSync(password, user.password);
if (!valid) {
return res.status(401).json({ message: 'Invalid credentials' });
}
// Fake JWT token
const token = `${user.id}:${Date.now()}`;
res.status(200).json({ token, user: { id: user.id, username: user.username } });
}
+32
View File
@@ -0,0 +1,32 @@
import { hashSync, compareSync } from 'bcryptjs';
import { v4 as uuidv4 } from 'uuid';
// In-memory store for demo purposes
let users = [];
export default function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' });
}
const { username, password } = req.body;
if (!username || !password) {
return res.status(400).json({ message: 'Username and password required' });
}
// Check if user exists
const existing = users.find(u => u.username === username);
if (existing) {
return res.status(400).json({ message: 'User already exists' });
}
const id = uuidv4();
const hashedPassword = hashSync(password, 10);
users.push({ id, username, password: hashedPassword });
// Return a fake JWT token (just a string)
const token = `${id}:${Date.now()}`;
res.status(201).json({ token, user: { id, username } });
}
+30
View File
@@ -0,0 +1,30 @@
import { useEffect } from 'react';
import { useRouter } from 'next/router';
export default function Dashboard() {
const router = useRouter();
useEffect(() => {
const token = localStorage.getItem('token');
if (!token) {
// redirect to login if not authenticated
router.push('/');
}
}, [router]);
const handleLogout = () => {
localStorage.removeItem('token');
router.push('/');
};
return (
<div style={{ padding: '2rem', textAlign: 'center' }}>
<h1>Expedição Gold</h1>
<p>Área do jogador - Em construção</p>
<p>Em breve: investir em expedições terrestres, marítimas, espirituais e cósmicas.</p>
<button onClick={handleLogout} style={{ marginTop: '1.5rem', padding: '0.5rem 1rem' }}>
Sair
</button>
</div>
);
}
+17
View File
@@ -0,0 +1,17 @@
import Link from 'next/link';
export default function Home() {
return (
<div style={{ padding: '2rem', textAlign: 'center' }}>
<h1>Bem-vindo à Expedição Gold</h1>
<p>
Invista em expedições e veja seu patrimônio crescer enquanto explora
terras, mares, o espírito e o cosmos.
</p>
<div style={{ marginTop: '2rem' }}>
<Link href="/login" style={{ marginRight: '1rem' }}>Entrar</Link>
<Link href="/signup">Cadastrar-se</Link>
</div>
</div>
);
}
+60
View File
@@ -0,0 +1,60 @@
import { useState } from 'react';
import { useRouter } from 'next/router';
export default function Login() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState(null);
const router = useRouter();
const handleSubmit = async e => {
e.preventDefault();
setError(null);
try {
const res = await fetch('/api/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await res.json();
if (!res.ok) throw new Error(data.message || 'Login failed');
localStorage.setItem('token', data.token);
router.push('/dashboard');
} catch (err) {
setError(err.message);
}
};
return (
<div style={{ maxWidth: 400, margin: '2rem auto', padding: '1rem', border: '1px solid #ddd', borderRadius: 8 }}>
<h2>Login - Expedição Gold</h2>
{error && <p style={{ color: 'red' }}>{error}</p>}
<form onSubmit={handleSubmit}>
<div>
<label>Usuário:</label>
<input
type="text"
value={username}
onChange={e => setUsername(e.target.value)}
required
style={{ width: '100%', padding: '0.5rem', marginTop: 0.5 }}
/>
</div>
<div>
<label>Senha:</label>
<input
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
required
style={{ width: '100%', padding: '0.5rem', marginTop: 0.5 }}
/>
</div>
<button type="submit" style={{ marginTop: 1, padding: '0.5rem 1rem' }}>Entrar</button>
</form>
<p>
Não tem conta? <a href="/signup" style={{ color: '#0066cc' }}>Cadastre-se</a>
</p>
</div>
);
}
+66
View File
@@ -0,0 +1,66 @@
import { useState } from 'react';
import { useRouter } from 'next/router';
export default function Register() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
const router = useRouter();
const handleSubmit = async e => {
e.preventDefault();
setError('');
setLoading(true);
try {
const res = await fetch('/api/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await res.json();
if (!res.ok) throw new Error(data.message || 'Signup failed');
alert('Conta criada com sucesso! Redirecionando para login...');
router.push('/');
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
};
return (
<div style={{ padding: '2rem', maxWidth: '400px', margin: '2rem auto' }}>
<h1>Cadastro - Expedição Gold</h1>
{error && <p style={{ color: 'red' }}>{error}</p>}
<form onSubmit={handleSubmit}>
<div style={{ marginBottom: '1rem' }}>
<label>Usuário:</label><br />
<input
type="text"
value={username}
onChange={e => setUsername(e.target.value)}
style={{ width: '100%', padding: '0.5rem', marginTop: '0.25rem' }}
required
/>
</div>
<div style={{ marginBottom: '1rem' }}>
<label>Senha:</label><br />
<input
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
style={{ width: '100%', padding: '0.5rem', marginTop: '0.25rem' }}
required
/>
</div>
<button type="submit" disabled={loading} style={{ padding: '0.5rem 1rem' }}>
{loading ? 'Criando...' : 'Criar conta'}
</button>
</form>
<p style={{ marginTop: '1rem', fontSize: '0.9rem', color: '#555' }}>
tem conta? <a href="/">Faça login</a>
</p>
</div>
);
}
+60
View File
@@ -0,0 +1,60 @@
import { useState } from 'react';
import { useRouter } from 'next/router';
export default function Signup() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState(null);
const router = useRouter();
const handleSubmit = async e => {
e.preventDefault();
setError(null);
try {
const res = await fetch('/api/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, password })
});
const data = await res.json();
if (!res.ok) throw new Error(data.message || 'Signup failed');
alert('Conta criada! Redirecionando para login...');
router.push('/login');
} catch (err) {
setError(err.message);
}
};
return (
<div style={{ maxWidth: 400, margin: '2rem auto', padding: '1rem', border: '1px solid #ddd', borderRadius: 8 }}>
<h2>Cadastro - Expedição Gold</h2>
{error && <p style={{ color: 'red' }}>{error}</p>}
<form onSubmit={handleSubmit}>
<div>
<label>Usuário:</label>
<input
type="text"
value={username}
onChange={e => setUsername(e.target.value)}
required
style={{ width: '100%', padding: '0.5rem', marginTop: 0.5 }}
/>
</div>
<div>
<label>Senha:</label>
<input
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
required
style={{ width: '100%', padding: '0.5rem', marginTop: 0.5 }}
/>
</div>
<button type="submit" style={{ marginTop: 1, padding: '0.5rem 1rem' }}>Criar conta</button>
</form>
<p>
tem conta? <a href="/login" style={{ color: '#0066cc' }}>Faça login</a>
</p>
</div>
);
}