Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Ajusta testes para as modificações feitas na autenticação de usuário #137

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vue-app/src/pages/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<script>
import router from "../routes/index";
import { autenticaUsuario } from "@/repositories/usuario/obterUsuarios.js";
import { autenticaUsuario } from "@/repositories/usuario/autenticarUsuario.js";
import LoadingComponent from "../components/Navegacao/LoadingComponent.vue";

export default {
Expand Down
29 changes: 29 additions & 0 deletions vue-app/src/repositories/usuario/autenticarUsuario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { authGuard } from "@/guards/authGuard";

const apiUrl = process.env.VUE_APP_API_URL;

// Função para autenticar o usuário
export async function autenticaUsuario(emailEntrada, senhaEntrada) {
try {
const resposta = await fetch(`${apiUrl}/autenticar`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email: emailEntrada, senha: senhaEntrada }),
});
if (!resposta.ok) {
throw new Error(`Erro ao autenticar usuário: ${resposta.statusText}`);
}
const data = await resposta.json();
if (data.success) {
authGuard(true, data.matricula);
return true;
} else {
authGuard(false);
return false;
}
} catch (erro) {
throw new Error(`Erro ao autenticar usuário: ${erro.message}`);
}
}
29 changes: 0 additions & 29 deletions vue-app/src/repositories/usuario/obterUsuarios.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
import { authGuard } from "@/guards/authGuard";

const apiUrl = process.env.VUE_APP_API_URL;

// Função para autenticar o usuário
export async function autenticaUsuario(emailEntrada, senhaEntrada) {
try {
const resposta = await fetch(`${apiUrl}/autenticar`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email: emailEntrada, senha: senhaEntrada }),
});
if (!resposta.ok) {
throw new Error(`Erro ao autenticar usuário: ${resposta.statusText}`);
}
const data = await resposta.json();
if (data.success) {
authGuard(true, data.matricula);
return true;
} else {
authGuard(false);
return false;
}
} catch (erro) {
throw new Error(`Erro ao autenticar usuário: ${erro.message}`);
}
}

export async function getUsuarios() {
try {
const resposta = await fetch(`${apiUrl}/usuario`);
Expand Down
Loading