Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Making web apps

Ashutosh Sajan AshutoshSajan

🤓
Making web apps
View GitHub Profile
View react main app component
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';
View react entry file
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';
View userReducer
const initialState = {
isLoading: true,
user: null
}
export default function usersReducer(state = initialState, action) {
switch (action.type) {
case 'LOGIN':
return {
...state,
View nodejs deleteQuestion function
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,
View node js verifyAdmin function
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",
View node js getQuiz function
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,
View verify jsonwebtoken function
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) => {
View node js user signup function
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
View node server entry file
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');
View handle login function
function handleLogin (){
let user = {
userName: 'Jhon Doe',
email: 'jhondoe@gmial.com',
password: 'superstar@123'
}
const BASE_URL = 'http://localhost:3000/api/v1'
fetch(BASE_URL + '/users/login', {