This commit is contained in:
Guillem George 2026-05-15 19:00:11 +02:00
parent 414aec97e5
commit 0fb4513b4b
2 changed files with 7 additions and 7 deletions

View file

@ -1,7 +1,7 @@
// FIXME: File that provide utils function for the debug page
import $ from "jquery";
import jwt_decode from "jwt-decode";
import { createAlert } from "../../utils/notify";
import {authedAPIRequest} from "../../utils/auth"
export async function displayStudentProfile() {
const token = localStorage.getItem("token");
@ -10,7 +10,7 @@ export async function displayStudentProfile() {
const _uid = decoded.uid;
// You have to write a request to fetch your informations
const request_result = null;
// const request_result = authedAPIRequest(`/api/students/${_uid}`, {method: "GET"});
if (request_result === null) {
createAlert(

View file

@ -9,9 +9,9 @@ async function sendRequest(endpoint, body) {
const request = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
// headers: {
// "Content-Type": "application/x-www-form-urlencoded",
// },
body: formData,
};
@ -130,7 +130,6 @@ async function authenticate() {
* body, rather than just the body
*/
async function authedAPIRequest(endpoint, options) {
console.log("Attemtping to make a request to: " + endpoint); // TODO remove
if (!authenticate()) {
return null;
}
@ -146,10 +145,11 @@ async function authedAPIRequest(endpoint, options) {
options.headers.Authorization = localStorage.getItem("token");
options.mode = "cors";
const full_endpoint = import.meta.env.VITE_URL + endpoint;
let response;
try {
response = await fetch(endpoint, options);
response = await fetch(full_endpoint, options);
if (!response.ok) {
throw new Error(response.statusText);
}