Skip to content

Instantly share code, notes, and snippets.

REACT RALLY 2018
Shirley Wu | @sxywu
Offers courses in Frontend Masters
D3 and React
https://twitter.com/sxywu/status/1030209690880303104
Main takeaway:
Use D3 for layout calculations and React for controlling rendering by passing props to SVG elements
@quiaro
quiaro / auth0Authentication.js
Last active December 29, 2017 02:47
Authentication in Graphcool via Auth0 ID Token
const jwt = require('jsonwebtoken');
const jwkRsa = require('jwks-rsa');
const fromEvent = require('graphcool-lib').fromEvent;
const verifyToken = token =>
new Promise((resolve, reject) => {
// Decode the JWT Token
const decoded = jwt.decode(token, { complete: true });
if (!decoded || !decoded.header || !decoded.header.kid) {
reject('Unable to retrieve key identifier from token');
@quiaro
quiaro / auth.js
Created November 15, 2017 17:35
Get ID token when authenticating via Auth0
import auth0 from 'auth0-js';
const CLIENT_DOMAIN = '__AUTH0_DOMAIN__';
const CLIENT_ID = '__AUTH0_CLIENT_ID__';
const SCOPE = 'openid email';
const REDIRECT = 'http://localhost:3000/callback';
const auth = new auth0.WebAuth({
domain: CLIENT_DOMAIN,
clientID: CLIENT_ID,
@quiaro
quiaro / auth0Authentication.graphql
Last active November 15, 2017 15:22
Graphcool custom mutation for authentication function
type AuthenticatedUser {
id: String!
token: String!
}
extend type Mutation {
authenticateUser(idToken: String!): AuthenticatedUser!
}
@quiaro
quiaro / LoginCallback.js
Created November 10, 2017 18:14
Functional Stateless React Component
import React from 'react';
export default () => (
<div>
<p>Login successful!</p>
</div>
)
@quiaro
quiaro / Home.js
Last active November 10, 2017 18:06
Login from Home component
import { login } from './common/auth';
export default () => {
login();
return null;
}
@quiaro
quiaro / auth.js
Created November 10, 2017 17:45
Authenticate via Auth0 Authentication API
import auth0 from 'auth0-js';
const CLIENT_DOMAIN = '__AUTH0_DOMAIN__';
const CLIENT_ID = '__AUTH0_CLIENT_ID__';
const SCOPE = 'openid';
const REDIRECT = 'http://localhost:3000/callback';
const auth = new auth0.WebAuth({
domain: CLIENT_DOMAIN,
clientID: CLIENT_ID,
@quiaro
quiaro / index.js
Created November 10, 2017 16:40
React App with two Routes
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import './index.css';
import Home from './Home';
import LoginCallback from './LoginCallback';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(
<Router>
@quiaro
quiaro / types.graphql
Created November 6, 2017 06:13
user type - Graphcool with Auth0
type User @model {
# Required system field:
id: ID! @isUnique # read-only (managed by Graphcool)
# Optional system fields (remove if not needed):
createdAt: DateTime! # read-only (managed by Graphcool)
updatedAt: DateTime! # read-only (managed by Graphcool)
email: String
auth0UserId: String @isUnique
@quiaro
quiaro / graphcool.yml
Last active November 15, 2017 18:58
service config - Graphcool with Auth0
types: ./types.graphql
functions:
authenticate:
handler:
code:
src: ./src/auth0/auth0Authentication.js
environment:
AUTH0_DOMAIN: ${env:AUTH0_DOMAIN}