This file contains hidden or 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
| var a = 1, b = 3 ,c = 4 , d = 5; | |
| var a = 1, | |
| b = 3, | |
| c = 5; | |
| var a = 1 | |
| ,b = 3 | |
| ,c = 5; |
This file contains hidden or 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
| const jwt = require("jsonwebtoken"); | |
| const User = require("../models/User"); | |
| function createToken (id, secret) { | |
| return jwt.sign({ | |
| userId: id | |
| }, | |
| secret, { | |
| expiresIn: "72h" | |
| }) |
This file contains hidden or 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
| const User = require("../models/User"); | |
| const bcrypt = require('bcrypt'); | |
| const jwtAuth = require('../utils/jwtAuth'); | |
| function loginUser (req, res){ | |
| User.findOne({ | |
| email: req.body.email | |
| }) | |
| .exec((err, user) => { | |
| if (err) { |
This file contains hidden or 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
| function handleLogin (){ | |
| let user = { | |
| userName: 'Jhon Doe', | |
| email: '[email protected]', | |
| password: 'superstar@123' | |
| } | |
| const BASE_URL = 'http://localhost:3000/api/v1' | |
| fetch(BASE_URL + '/users/login', { |
This file contains hidden or 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
| require('dotenv').config(); | |
| const createError = require('http-errors'); | |
| const express = require('express'); | |
| const path = require('path'); | |
| const cookieParser = require('cookie-parser'); | |
| const logger = require('morgan'); | |
| const mongoose = require('mongoose'); | |
| const cors = require("cors"); | |
| const indexRouter = require('./routes/index'); |
This file contains hidden or 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
| const User = require("../models/User"); | |
| const bcrypt = require('bcrypt'); | |
| const jwtAuth = require('../utils/jwtAuth'); | |
| module.exports = { | |
| // create/register user | |
| registerUser: (req, res) => { | |
| User.findOne({ | |
| email: req.body.email |
This file contains hidden or 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
| function verifyToken (req, res, next) { | |
| var token = req.headers.Authorization || req.headers.authorization || ""; | |
| if (!token) { | |
| res.status(401).json({ | |
| success: false, | |
| message: "please authenticate." | |
| }); | |
| } else if (token) { | |
| jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => { |
This file contains hidden or 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
| function getQuestion(req, res) { | |
| const id = req.params.id; | |
| Question.findOne({ | |
| _id: id | |
| }, (err, question) => { | |
| if (err) { | |
| res.status(500).json({ | |
| success: false, | |
| error: err, |
This file contains hidden or 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
| function isAdmin (req, res, next) { | |
| const id = req.user.userId; | |
| User.findOne({ | |
| _id: id | |
| }, (err, user) => { | |
| if (err) { | |
| res.status(500).json({ | |
| success: false, | |
| message: "server error", |
This file contains hidden or 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
| function deleteQuestion (req, res) { | |
| const id = req.params.id; | |
| Question.findOneAndDelete({ | |
| _id: id | |
| }, (err, question) => { | |
| if (err) { | |
| res.status(500).json({ | |
| success: false, | |
| error: err, |
OlderNewer