127 lines
3.6 KiB
JavaScript
127 lines
3.6 KiB
JavaScript
import fetch from "node-fetch";
|
|
|
|
const SUPABASE_URL = "https://yuanqfswhberkoevtmfr.supabase.co";
|
|
const SUPABASE_ANON_KEY =
|
|
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ";
|
|
|
|
const timestamp = Date.now();
|
|
const email = `teste${timestamp}@gmail.com`;
|
|
const password = "SenhaSegura123!";
|
|
|
|
async function cadastrarUsuario() {
|
|
console.log("\n📝 ETAPA 1: Cadastrando novo usuário...\n");
|
|
console.log(`Email: ${email}`);
|
|
console.log(`Senha: ${password}\n`);
|
|
|
|
try {
|
|
const response = await fetch(`${SUPABASE_URL}/auth/v1/signup`, {
|
|
method: "POST",
|
|
headers: {
|
|
apikey: SUPABASE_ANON_KEY,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
email: email,
|
|
password: password,
|
|
data: {
|
|
nome: "Teste Login",
|
|
telefone: "79999999999",
|
|
cpf: "12345678900",
|
|
dataNascimento: "1990-01-01",
|
|
endereco: JSON.stringify({
|
|
rua: "Rua Teste",
|
|
numero: "123",
|
|
bairro: "Centro",
|
|
cidade: "Aracaju",
|
|
estado: "SE",
|
|
cep: "49000-000",
|
|
}),
|
|
},
|
|
}),
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
console.log("✅ CADASTRO SUCESSO!");
|
|
console.log(`User ID: ${data.user?.id}`);
|
|
console.log(`Email: ${data.user?.email}`);
|
|
console.log(
|
|
`Email confirmado: ${data.user?.email_confirmed_at ? "SIM" : "NÃO"}`
|
|
);
|
|
return data;
|
|
} else {
|
|
console.log("❌ CADASTRO FALHOU");
|
|
console.log(JSON.stringify(data, null, 2));
|
|
return null;
|
|
}
|
|
} catch (error) {
|
|
console.error("❌ Erro no cadastro:", error.message);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function fazerLogin() {
|
|
console.log("\n\n🔐 ETAPA 2: Fazendo login com o usuário cadastrado...\n");
|
|
console.log(`Email: ${email}`);
|
|
console.log(`Senha: ${password}\n`);
|
|
|
|
try {
|
|
const response = await fetch(
|
|
`${SUPABASE_URL}/auth/v1/token?grant_type=password`,
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
apikey: SUPABASE_ANON_KEY,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
email: email,
|
|
password: password,
|
|
}),
|
|
}
|
|
);
|
|
|
|
const data = await response.json();
|
|
|
|
console.log(`Status: ${response.status}\n`);
|
|
|
|
if (response.ok) {
|
|
console.log("✅ LOGIN SUCESSO!");
|
|
console.log(`\nToken JWT: ${data.access_token?.substring(0, 50)}...`);
|
|
console.log(`User ID: ${data.user?.id}`);
|
|
console.log(`Email: ${data.user?.email}`);
|
|
console.log(
|
|
`Email confirmado: ${data.user?.email_confirmed_at ? "SIM" : "NÃO"}`
|
|
);
|
|
console.log(
|
|
"\n✅ CONCLUSÃO: Sistema funcionando 100%! Login imediato após cadastro.\n"
|
|
);
|
|
} else {
|
|
console.log("❌ LOGIN FALHOU");
|
|
console.log("\nResposta completa:");
|
|
console.log(JSON.stringify(data, null, 2));
|
|
}
|
|
} catch (error) {
|
|
console.error("❌ Erro ao fazer login:", error.message);
|
|
}
|
|
}
|
|
|
|
async function testarFluxoCompleto() {
|
|
const cadastroResult = await cadastrarUsuario();
|
|
|
|
if (cadastroResult) {
|
|
// Aguardar 2 segundos para garantir que o usuário está no banco
|
|
console.log("\n⏳ Aguardando 2 segundos...");
|
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
|
|
await fazerLogin();
|
|
} else {
|
|
console.log(
|
|
"\n❌ Não foi possível prosseguir com o login porque o cadastro falhou."
|
|
);
|
|
}
|
|
}
|
|
|
|
testarFluxoCompleto();
|