Skip to content

Instantly share code, notes, and snippets.

View tkssharma's full-sized avatar
🎯
only JS

codewithtkssharma tkssharma

🎯
only JS
View GitHub Profile
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);
});
}
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');
}
}
};
const app = express();
app.use(bodyParser.json());
app.use(
'/graphql',
graphqlHttp({
schema: graphQlSchema,
rootValue: graphQlResolvers,
graphiql: true
})
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,
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)
};
function Todo() {
const [tasks, setTasks] = useState([
{
title: "Grab some Pizza",
completed: true
},
{
title: "Do your workout",
completed: true
},
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 }) => ({
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,
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
function LocalStorageHook() {
const [count, setCount] = useState(() => {
let value;
try {
value = JSON.parse(
window.locastorage.getItem('count') || '0'
)
} catch (e) {