Skip to content

Instantly share code, notes, and snippets.

View VinayaSathyanarayana's full-sized avatar

Vinaya Sathyanarayana VinayaSathyanarayana

View GitHub Profile

How to set up a NodeJS website with Authentication and Back office (and Blog)

In this tutorial we're going to build a NodeJS website with the following features:

  • User authentication
  • Back office
  • Blog (optional)

The first to parts of the tutorial are meant to quickly set you up and running. The third part is a more in depth explanation of some points I find important, so feel free to read them later as you need.

keystonejs notes

Creating custom keystone Lists (models)

  • keystone lists or models basically map back to mongodb collections
  • each property you add into the model object will become a field in the keystone admin UI. The model itself will become a mongo collection in the db and the fields will also be stored under the collection.
  • each property you define in the model needs to have a type. Types are defined by the keystone api. There are many types that are built into keystone a list of them can be found Here

How to create a new list

@VinayaSathyanarayana
VinayaSathyanarayana / notes.md
Created November 15, 2017 17:38 — forked from JedWatson/notes.md
Notes on how to create a new field type for Keystone

Creating new Field Types for KeystoneJS

We're currently working on making it easier to add new field types to KeystoneJS as plugins.

In the meantime, if you'd like to work on your own field type, hopefully this guide will point you in the right direction.

Keystone fields require the following:

  • a {fieldType}.js file in ./lib/fieldTypes that controls the field and encapsulates options support, underscore functions, validation and updating
  • the {fieldType}.js file needs to be included by ./lib/fieldTypes/index.js
@VinayaSathyanarayana
VinayaSathyanarayana / signup.jade
Created November 15, 2017 17:40 — forked from robksawyer/signup.jade
A pretty basic registration form for KeystoneJS.
// @file signup.jade
// @path /templates/views/user/signup.jade
// @description Form that user sees when signing up.
//
extends ../../layouts/default
block intro
.container
h1= 'Sign up for Little B.O.M'
@VinayaSathyanarayana
VinayaSathyanarayana / keystone.js
Created November 15, 2017 17:40 — forked from riyadhalnur/keystone.js
Add more options to the express app when using KeystoneJS
var keystone = require('keystone');
var express = require('express');
var body = require('body-parser');
var helmet = require('helmet');
var app = express();
app.use(body.urlencoded({ extended: false }));
app.use(body.json());
app.use(helmet());
@VinayaSathyanarayana
VinayaSathyanarayana / RepeatableFields.js
Created November 15, 2017 17:41 — forked from ryan-haskell/RepeatableFields.js
Used for expanding KeystoneJS fields, and flattening the response
const getRange = (start, end) => {
let list = []
if (start <= end) {
for (let i = start; i <= end; i++)
list.push(i)
}
return list
}
const RepeatableField = (fields, prefix) => ({
@VinayaSathyanarayana
VinayaSathyanarayana / models-Page.js
Created November 15, 2017 17:41 — forked from timboslice69/models-Page.js
Role based security in KeystoneJS
var keystone = require('keystone'),
// pull in the schemaPermissions lib
// rootRequire is a custom function that fixes the path to always be from the root of the application
schemaPermissions = rootRequire('lib/schemaPermissions'),
Types = keystone.Field.Types;
/**
* Page Model
* ==========
*/
@VinayaSathyanarayana
VinayaSathyanarayana / 1-proposal.md
Created November 15, 2017 17:42 — forked from JedWatson/1-proposal.md
Proposal: adding reverse-relationship population to Mongoose (as implemented in KeystoneJS)

I've developed a useful feature in KeystoneJS that lets you populate a relationship from either side, while only storing the data on one side, and am looking for feedback on whether it is something that could / should be brought back into mongoose itself. (It might be possible to add as a separate package but I suspect there'd be too much rewriting of mongoose internals for that to be a good idea).

I've added this as an issue in mongoose for consideration: #1888 but am leaving this gist in place because the examples are easier to read.

I've used Posts and Categories as a basic, contrived example to demonstrate what I'm talking about here; in reality you'd rarely load all the posts for a category but there are other real world cases where it's less unreasonable you'd want to do this, and Posts + Categories is an easy way to demo it.

The problem

The built-in population feature is really useful; not just for