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
arr.reduce(callback(accumulator, currentValue[, index[, array]]), [, initialValue]) |
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
import React, { Component } from 'react' | |
import io from 'socket.io-client' | |
import jwtDecode from 'jwt-decode' | |
import { notify } from 'react-notify-toast' | |
import OAuth from './OAuth' | |
import Loading from './Loading' | |
import Header from './Header' | |
import Footer from './Footer' | |
import api from './api' | |
import { API_URL } from './config' |
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 express = require('express') | |
const path = require('path') | |
const fs = require('fs') | |
const https = require('https') | |
const http = require('http') | |
const passport = require('passport') | |
const session = require('express-session') | |
const cors = require('cors') | |
const socketio = require('socket.io') |
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
module.exports = profile => { | |
const { provider } = profile | |
switch(provider) { | |
case 'twitter': | |
return { | |
name: profile.username, | |
photo: profile.photos[0].value.replace(/_normal/, '') | |
} | |
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 express = require('express') | |
const router = express.Router() | |
const passport = require('passport') | |
const authController = require('./auth.controller') | |
// Setting up the passport middleware for each of the OAuth providers | |
const twitterAuth = passport.authenticate('twitter') | |
const googleAuth = passport.authenticate('google', { scope: ['profile', 'email'] }) | |
const facebookAuth = passport.authenticate('facebook') | |
const githubAuth = passport.authenticate('github') |
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('./user.model') | |
const { providers, JWT_EXPIRY, JWT_SECRET } = require('../config') | |
const createAuthToken = user => | |
jwt.sign({user}, JWT_SECRET, { | |
subject: user.email, | |
expiresIn: JWT_EXPIRY, | |
algorithm: 'HS256' | |
}) |
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 passport = require('passport') | |
const { Strategy: TwitterStrategy } = require('passport-twitter') | |
const { OAuth2Strategy: GoogleStrategy } = require('passport-google-oauth') | |
const { Strategy: FacebookStrategy } = require('passport-facebook') | |
const { Strategy: GithubStrategy} = require('passport-github') | |
const { Strategy: JwtStrategy } = require('passport-jwt') | |
const User = require('./user.model') | |
const normalizeProfileData = require('./normalize.profile.data') | |
const { | |
TWITTER_CONFIG, GOOGLE_CONFIG, FACEBOOK_CONFIG, GITHUB_CONFIG, JWT_CONFIG |
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 mongoose = require('mongoose') | |
const Schema = mongoose.Schema | |
const { providers } = require('../config') | |
// | |
const providerFields = providers.reduce((obj, provider) => { | |
obj[provider] = { | |
name: { | |
type: String | |
}, |
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 render = (() => { | |
const _todoHTML = todo => { | |
const { editing, text, done, id } = todo | |
const todoText = editing | |
? `<form> | |
<input value='${text}' data-id='${id}'> | |
</form>` | |
: `<div class='text ${done}'>${text}</div>` |
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 store = (() => { | |
const todos = [] | |
function addToStore(todo) { | |
todo.editing = false | |
this.todos = [todo, ...this.todos] | |
} | |
function deleteFromStore(id) { |
NewerOlder