This commit is contained in:
Guillem George 2026-05-15 20:13:34 +02:00
parent 0fb4513b4b
commit 0114214995
2 changed files with 5 additions and 3 deletions

View file

@ -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 = authedAPIRequest(`/api/students/${_uid}`, {method: "GET"}); const request_result = await authedAPIRequest(`/students/${_uid}`, {method: "GET"});
if (request_result === null) { if (request_result === null) {
createAlert( createAlert(

View file

@ -136,16 +136,17 @@ async function authedAPIRequest(endpoint, options) {
if (!options.method) { if (!options.method) {
console.error("Invalid parameter: options (missing method)"); console.error("Invalid parameter: options (missing method)");
return null
} }
if (!options.headers) { if (!options.headers) {
options.headers = {}; options.headers = {};
} }
options.headers.Authorization = localStorage.getItem("token"); options.headers.Authorization = "Bearer " + localStorage.getItem("token");
options.mode = "cors"; options.mode = "cors";
const full_endpoint = import.meta.env.VITE_URL + endpoint; const full_endpoint = import.meta.env.VITE_URL + "/api" + endpoint;
let response; let response;
try { try {
@ -163,6 +164,7 @@ async function authedAPIRequest(endpoint, options) {
} }
localStorage.clear(); localStorage.clear();
alert("Redirecting to logging page")
redirect.redirectToLoginPage(); redirect.redirectToLoginPage();
return null; return null;
} }