hhhhhnnn mimimimimimimimi
This commit is contained in:
parent
0114214995
commit
441f00507d
4 changed files with 68 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
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"
|
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,9 @@ 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 = await authedAPIRequest(`/students/${_uid}`, {method: "GET"});
|
const request_result = await authedAPIRequest(`/students/${_uid}`, {
|
||||||
|
method: "GET",
|
||||||
|
});
|
||||||
|
|
||||||
if (request_result === null) {
|
if (request_result === null) {
|
||||||
createAlert(
|
createAlert(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,16 @@
|
||||||
// FIXME: This is the entry point of the application, write your code here
|
import { initSocket } from "../utils/streams";
|
||||||
|
|
||||||
import { calculateLayout } from "./utils";
|
import { calculateLayout } from "./utils";
|
||||||
|
import { authenticate } from "../utils/auth";
|
||||||
|
|
||||||
// Initialize the layout
|
// Initialize the layout
|
||||||
calculateLayout();
|
calculateLayout();
|
||||||
|
|
||||||
|
async () => {
|
||||||
|
// ? Not sure
|
||||||
|
if (!(await authenticate())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
initSocket();
|
||||||
|
// subscribe()
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ async function authenticate() {
|
||||||
const refresh_token = localStorage.getItem("refresh_token");
|
const refresh_token = localStorage.getItem("refresh_token");
|
||||||
|
|
||||||
if (refresh_token !== null) {
|
if (refresh_token !== null) {
|
||||||
return true;
|
return await refreshToken(refresh_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
|
@ -130,13 +130,13 @@ 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) {
|
||||||
if (!authenticate()) {
|
if (!(await authenticate())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.method) {
|
if (!options.method) {
|
||||||
console.error("Invalid parameter: options (missing method)");
|
console.error("Invalid parameter: options (missing method)");
|
||||||
return null
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.headers) {
|
if (!options.headers) {
|
||||||
|
|
@ -159,12 +159,12 @@ async function authedAPIRequest(endpoint, options) {
|
||||||
const response_err = await response.text();
|
const response_err = await response.text();
|
||||||
|
|
||||||
if (response_err.includes("Token expired")) {
|
if (response_err.includes("Token expired")) {
|
||||||
refreshToken(null);
|
await refreshToken(null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
alert("Redirecting to logging page")
|
alert("Redirecting to logging page");
|
||||||
redirect.redirectToLoginPage();
|
redirect.redirectToLoginPage();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { io } from "socket.io-client";
|
||||||
|
// import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
// FIXME: This file should handle the sockets and the subscriptions
|
// FIXME: This file should handle the sockets and the subscriptions
|
||||||
// Exports must include
|
// Exports must include
|
||||||
// - initSocket (initialize the connection to the socket server)
|
// - initSocket (initialize the connection to the socket server)
|
||||||
|
|
@ -7,3 +10,47 @@
|
||||||
// - subscribe (subscribe to a room's stream or chat)
|
// - subscribe (subscribe to a room's stream or chat)
|
||||||
// - unsubscribe (unsubscribe from a room's stream or chat)
|
// - unsubscribe (unsubscribe from a room's stream or chat)
|
||||||
// - sendMessage (send a message to a room's chat)
|
// - sendMessage (send a message to a room's chat)
|
||||||
|
|
||||||
|
let socket = null;
|
||||||
|
// let uuid = uuidv4();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the socket when authenticated
|
||||||
|
* returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async function initSocket() {
|
||||||
|
console.debug("Initializing socket connection");
|
||||||
|
const token = localStorage.getItem("token");
|
||||||
|
|
||||||
|
const host = import.meta.env.VITE_HOST;
|
||||||
|
const port = import.meta.env.VITE_PORT;
|
||||||
|
const wsUri = "ws://" + host + (port ? ":" + port : "");
|
||||||
|
|
||||||
|
socket = io(wsUri, {
|
||||||
|
reconnectionDelayMax: 10000,
|
||||||
|
extraHeaders: {
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.debug("Socket active: " + socket.active);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// async function subscribe(room) {
|
||||||
|
|
||||||
|
// if (!room)
|
||||||
|
// room = "epi-place"
|
||||||
|
|
||||||
|
// console.warn("Skipping room susbscription (not implemented)")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async function unsubscribe() {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// async function sendMessage() {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
export { initSocket, socket };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue