Skip to content

Instantly share code, notes, and snippets.

@JedWatson
JedWatson / API-Auth-With-KeystoneJS.md
Last active April 16, 2023 02:11
API Auth with KeystoneJS

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout
@JedWatson
JedWatson / UserStore.js
Created March 26, 2015 00:40
Simple store-prototype example for a User Store + View
var Store = require('store-prototype');
var UserStore = new Store();
var users = {};
var loaded = false;
UserStore.extend({
loadUsers: function() {
loadUsersSomehow(function(err, results) {
users = results;
@JedWatson
JedWatson / renderComponentToStringAndCSS.js
Last active August 29, 2015 14:24
React.renderComponentToStringAndCSS
var MyComponent = React.createComponent({
render () {
return <div style={{ color: 'blue' }}>Hello World</div>;
});
var page = React.renderComponentToStringAndCSS(MyComponent);
// value of page:
page = {
html: '<div className="__a" data-reactid=".abc" data-react-checksum="123" data-react-classname="__a">Hello World</div>',
@JedWatson
JedWatson / Flick.js
Created July 12, 2015 04:32
Declarative Interaction Component
<Flick settings={...}>
{velocityDelta =>
<Spring
currentVelocity={currentVelocity => velocityDelta === 0 ? currentVelocity :
increase(currentVelocity, velocityDelta)
}
endValue={...}>
{currentValues => <div />}
</Spring>
}
@JedWatson
JedWatson / styles.jsx
Created April 5, 2016 03:14
A simple thought experiment demonstrating concepts I'm thinking about for styling react components in javascript
import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import useSheet from 'react-jss';
import CloudinaryImage from './CloudinaryImage';
const Author = ({image, name}, {theme}) => {
const classes = useSheet(stylesheet, theme);
const { authorKey, bio, id, image, name, summary, urlPath } = this.props;
@JedWatson
JedWatson / files.js
Created April 8, 2016 11:39
File Field Scratchpad
keystone.init({
...options
});
var S3Storage = require('keystone-storage-s3');
keystone.addStorage('s3bucket1', S3Storage, {
key: 'my key',
bucket: 'keystone-stuff',
secret: 'abracadabra',
@JedWatson
JedWatson / localfile.js
Created April 11, 2016 14:10
LocalFile Contents Scratch
{ fieldname: 'file',
originalname: 'Advanced example.md',
name: '1458848e82f2de780e5ad963d93606aa.md',
encoding: '7bit',
mimetype: 'text/markdown',
path: '/var/folders/ck/y02pffhs31xd_k4xc9xmn3hw0000gn/T/1458848e82f2de780e5ad963d93606aa.md',
extension: 'md',
size: 7703,
truncated: false,
buffer: null } }