Skip to content

Instantly share code, notes, and snippets.

View AshutoshSajan's full-sized avatar
🤓
Making web apps

Ashutosh Sajan AshutoshSajan

🤓
Making web apps
View GitHub Profile
import React, { Component } from 'react';
import { Switch, Route, withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import Login from './user/containers/Login';
import Register from './user/containers/Register';
import Header from './app/componets/Header';
import AdminDashboard from './admin/containers/AdminDashboard';
import UserDashboard from './user/containers/UserDashboard';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter as Router } from 'react-router-dom';
import App from './App.jsx';
import 'bulma/css/bulma.css';
import './stylesheets/index.css';
const initialState = {
isLoading: true,
user: null
}
export default function usersReducer(state = initialState, action) {
switch (action.type) {
case 'LOGIN':
return {
...state,
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,
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",
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,
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) => {
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
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');
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', {