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 $ from "jquery";
import jwt_decode from "jwt-decode"; import jwt_decode from "jwt-decode";
import { createAlert } from "../../utils/notify"; import { createAlert } from "../../utils/notify";
import {authedAPIRequest} from "../../utils/auth"
export async function displayStudentProfile() { export async function displayStudentProfile() {
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
@ -10,7 +10,7 @@ export async function displayStudentProfile() {
const _uid = decoded.uid; const _uid = decoded.uid;
// You have to write a request to fetch your informations // 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) { if (request_result === null) {
createAlert( createAlert(

View file

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