Skip to content

Commit

Permalink
Merge pull request #137 from unb-mds/133-fix-dados-de-todos-os-usuari…
Browse files Browse the repository at this point in the history
…os-no-client-side

test: Ajusta testes para as modificações feitas na autenticação de usuário
  • Loading branch information
ana-pfeilsticker authored Aug 14, 2024
2 parents 818b558 + 44254c4 commit fac141e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
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

0 comments on commit fac141e

Please sign in to comment.