Skip to content

Instantly share code, notes, and snippets.

View OlivierJM's full-sized avatar

ojm OlivierJM

View GitHub Profile
@OlivierJM
OlivierJM / auth-server.js
Last active May 27, 2019 16:58
demo on how to perform basic authentication and authorization in graphql
const { ApolloServer, gql } = require("apollo-server");
const jwt = require("jsonwebtoken");
const mongoose = require("mongoose");
const bcrypt = require("bcrypt");
const pick = require("lodash").pick;
// configure the user collection
const userSchema = mongoose.Schema({
email: String,
password: String
const SECRET="createaverystrongsecretthatalsoincludes2423412wdsa324e34e"
const server = new ApolloServer({
schema,
context: ({ req }) => {
const { user } = req
// the user and secret we are passing here is what we access in every resolver
return {
user,
SECRET,
Mutation: {
async register(root, { email, password }) {
// { email, password } this is coming from the args(arguments) that are passed down when registering
let user = new User()
user.email = email
// here we hash the password using bcrypt and store the hashed value in the db
user.password = await bcrypt.hash(password, 12)
// save the user to the db
// it shouldn't matter what db you are using
return user.save()

Theory

  1. Briefly explain the difference between props and states

  2. What are synthetic events in React?

  3. What are refs and give example of a use case?

<ErrorBoundary>
<ComponentThatCanCauseAnError />
{ /* If you want you can even nest this */ }
<ErrorBoundary>
<AnotherComponent />
</ErrorBoundary>
</ErrorBoundary>
import React, { Component } from 'react';
import { PropTypes } from 'prop-types';
import { Meteor } from 'meteor/meteor';
import { formatText } from '../utils/utils';
export default class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
"titles": {
"addreference": "Ajouter Références",
"referenceDisplaced": "Références affichées",
"feedback": "Commentaire",
"source": "Source",
"usersfeedback": "Commentaires de l'utilisateur",
"notifications": "Notifications",
"bookmarks": "Signets"
}
// this is truncated and don't mind this comment in JSON 😉
{
"_locale": "en-us",
"_namespace": "common",
"language": {
"enUS": "English - U.S.",
"esES": "Spanish - SP",
"frFr": "French - FR",
"Language": "Language"
},
// This file has been truncated for brevity
import React, { Fragment, Component } from 'react';
import { Meteor } from 'meteor/meteor';
import PropTypes from 'prop-types';
import i18n from 'meteor/universe:i18n';
import { ThemeContext } from '../../containers/AppWrapper';
const T = i18n.createComponent();
/* eslint class-methods-use-this: "off" */
/* eslint import/no-unresolved: "off" */
import React, { Fragment } from 'react';
import { PropTypes } from 'prop-types';
import Header from '../components/layouts/Header';
export const ThemeContext = React.createContext();
export default class AppWrapper extends React.Component {
state = {