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 from 'react'; | |
| export default function AboutView() { | |
| return ( | |
| <div className="about-view m-3"> | |
| <h1>ABOUT PAGE</h1> | |
| </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
| import React, { Component } from 'react'; | |
| import Header from 'components/Header'; | |
| import Routes from 'routes'; | |
| import LoginFormModal from 'components/LoginForm'; | |
| import './App.scss'; | |
| export class App extends Component { | |
| state = { |
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 from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import createHistory from 'history/createBrowserHistory'; | |
| import { createStore, combineReducers, applyMiddleware } from 'redux'; | |
| import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux'; | |
| import { Provider } from 'react-redux'; | |
| import createSagaMiddleware from 'redux-saga'; | |
| import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'; | |
| import 'bootstrap'; |
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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>AUTH FLOW</title> | |
| <meta name="description" content=""> | |
| <!-- Mobile-friendly viewport --> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| </head> | |
| <body> |
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
| exports.getLoggedUser = async (ctx) => { | |
| if (ctx.isAuthenticated()) { | |
| const reqUserId = ctx.req.user.id; | |
| let user = null; | |
| await getAsync('usersMockDatabase').then((users) => { | |
| user = JSON.parse(users).find(currUser => currUser.id === reqUserId); | |
| }); | |
| if (user) { | |
| delete user.password; | |
| ctx.response.body = user; |
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
| passport.use( | |
| new FacebookStrategy( | |
| { | |
| clientID: config.facebookAuth.clientID, | |
| clientSecret: config.facebookAuth.clientSecret, | |
| callbackURL: config.facebookAuth.callbackURL, | |
| profileFields: [ | |
| 'id', | |
| 'displayName', | |
| 'picture.width(200).height(200)', |
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
| passport.use( | |
| new LocalStrategy( | |
| { | |
| usernameField: 'email', | |
| passwordField: 'password', | |
| }, | |
| async (email, password, done) => { | |
| let user = null; | |
| await getAsync('usersMockDatabase').then((users) => { | |
| const currUsers = JSON.parse(users); |
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 bcrypt = require('bcrypt'); | |
| const passport = require('koa-passport'); | |
| const FacebookStrategy = require('passport-facebook').Strategy; | |
| const LocalStrategy = require('passport-local').Strategy; | |
| const config = require('../serverConfig'); | |
| const { db } = require('../server'); | |
| const { promisify } = require('util'); | |
| const getAsync = promisify(db.get).bind(db); |
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 auth = require('./controllers/auth'); | |
| const router = new Router(); | |
| router | |
| /* Handle Login POST */ | |
| .post('/login', ctx => passport.authenticate('local', (err, user) => { | |
| if (!user) { | |
| ctx.throw(401, err); | |
| } else { | |
| ctx.body = user; |
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
| // create mock database with one user | |
| const db = redis.createClient(); | |
| db.on('error', (err) => { | |
| console.log(`Redis Error ${err}`); | |
| }); | |
| db.set('usersMockDatabase', JSON.stringify([ | |
| { | |
| id: 1, | |
| email: 'chouomam@chouman.com', | |
| // "test" -- generated by bcrypt calculator |