This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. create a backend file with middleware function to check if user is logged in within 3 steps, note that the following snippet is a sample function asserting that a given token not only follows a proper JWT format, but also it's signature matches during the encoding and decoding process, so as to grant actions entitled to a privileged user | |
// 1.1 import modules | |
const jwt = require("jsonwebtoken"); | |
const JWT_SECRET = process.env.JWT_SECRET; | |
// 1.2 declare token verification function | |
function verifyToken(req, res, next) { | |
const authHeader = req.headers.authorization; | |
// 1.2.1 check if the header contains the authorization information | |
if (authHeader === null || authHeader === undefined || !authHeader.startsWith("Bearer ")) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create a class to modal MCQ which takes in question, choice, answer and category as its parameter | |
class MCQ { | |
constructor(question, choice, answer, category) { | |
this.question = question; | |
this.choice = choice; | |
this.answer = answer; | |
this.category = category; | |
this.userAnswer = ""; | |
} | |
//write a method to display question and choices format |