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
static registerUser(dbContext, payload) { | |
return userHelper | |
.findByEmail(dbContext, payload.email) | |
.then(user => { | |
if (!user) { | |
const data = { ...payload, password: userHelper.hashPassword(payload.password) }; | |
return dbContext.query(userModel.createUser(data)).then(() => { | |
return Promise.resolve(null); | |
}); | |
} |
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 getLoggedInUser = req => { | |
const token = req.headers['x-auth-token']; | |
if (token) { | |
try { | |
return jwt.verify(token, process.env.JWT_SECRET); | |
} catch(error) { | |
throw new Error('Session expired'); | |
} | |
} | |
}; |
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 app = express(); | |
app.use(bodyParser.json()); | |
app.use( | |
'/graphql', | |
graphqlHttp({ | |
schema: graphQlSchema, | |
rootValue: graphQlResolvers, | |
graphiql: true | |
}) |
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 ReactDOM from "react-dom"; | |
import React, { useReducer, useRef } from "react"; | |
const App = () => { | |
const inputRef = useRef(); | |
const [items, dispatch] = useReducer((state, action) => { | |
switch (action.type) { | |
case "ADD": | |
return [ | |
...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 ReactDOM from "react-dom"; | |
import React, { useReducer, useState } from "react"; | |
const App = () => { | |
const [data, setData] = useState(''); | |
const [item, setItem] = useState([]); | |
const HandleChange = (e) => { | |
setData(e.target.value) | |
}; |
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 Todo() { | |
const [tasks, setTasks] = useState([ | |
{ | |
title: "Grab some Pizza", | |
completed: true | |
}, | |
{ | |
title: "Do your workout", | |
completed: true | |
}, |
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"; | |
const ToDoContext = React.createContext(); | |
class ToDoList extends React.Component { | |
state = { | |
list: [], | |
todo: "" | |
}; | |
createNewToDoItem = () => { | |
this.setState(({ list, todo }) => ({ |
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 { ApolloClient } from 'apollo-client'; | |
import { HttpLink } from 'apollo-link-http'; | |
import { ApolloLink, concat } from 'apollo-link'; | |
const httpLink = new HttpLink({ uri: '/graphql' }); | |
// registering middlewares [authMiddleware, otherMiddleware ] | |
const authMiddleware = new ApolloLink((operation, forward) => { | |
// add the authorization to the headers | |
operation.setContext({ | |
headers: { | |
authorization: localStorage.getItem('token') || null, |
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 gql from 'graphql-tag'; | |
import { Query } from 'react-apollo'; | |
import SpacexComponent from './Space'; | |
import Mock from './Space/mock'; | |
const GET_SPACEX_DATA = gql` | |
{ | |
launchesPast(limit: 10) { | |
mission_name |
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 LocalStorageHook() { | |
const [count, setCount] = useState(() => { | |
let value; | |
try { | |
value = JSON.parse( | |
window.locastorage.getItem('count') || '0' | |
) | |
} catch (e) { |