Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Khan danielkhan

  • Sentry
  • Linz / Austria
  • Twitter @dkhan
View GitHub Profile
View lambdaIndex.js
console.log('Loading function');
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
/**
* Demonstrates a simple HTTP endpoint using API Gateway. You have full
* access to the request and response payload, including headers and
View loginRoute.js
router.post('/login', async (req, res) => {
try {
return passport.authenticate('local', { session: false }, (err, user) => {
if (err || !user) {
res.status(404).json({ error: 'Invalid username or password' });
}
return req.login(user, { session: false }, (loginErr) => {
if (loginErr) {
res.status(500).json({ error: loginErr });
}
View ContactModel.js
const mongoose = require('mongoose');
const ContactSchema = mongoose.Schema({
user_id: {
type: mongoose.Schema.ObjectId,
required: true,
},
firstname: {
type: String,
required: true,
View passport.js
const passport = require('passport');
const passportJWT = require('passport-jwt');
const JWTStrategy = passportJWT.Strategy;
const ExtractJWT = passportJWT.ExtractJwt;
const LocalStrategy = require('passport-local').Strategy;
const UserService = require('../services/UserService');
module.exports = (config) => {
View eslintrc2.js
module.exports = {
"extends": "airbnb-base",
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
"no-underscore-dangle": ["error", { "allow": ["_id"] }],
"no-param-reassign": ["error", { "props": false }],
}
};
View register swagger
/**
* @swagger
* /users/register:
* post:
* parameters:
* - in: body
* name: user
* description: The user to create.
* schema:
* $ref: "#/definitions/User"
View passwordhash.js
UserSchema.pre('save', function preSave(next) {
const user = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified('password')) return next();
// generate a salt
return bcrypt.genSalt(10, (err, salt) => {
if (err) return next(err);
View contactTest1.js
// /tests/routes/api/v1/contacts/indexTest.js
/* eslint-disable no-unused-expressions */
const chai = require('chai');
const chaiHttp = require('chai-http');
chai.use(chaiHttp);
chai.should();
const { expect } = chai;
const config = require('../../../../../config').test;
View .eslinrc-test.js
module.exports = {
extends: "airbnb-base",
rules: {
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }] ,
"no-param-reassign": ["error", { "props": false }],
},
env: {
node: true,
mocha: true
}
View .eslintrs.js
module.exports = {
"extends": "airbnb-base",
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
"no-param-reassign": ["error", { "props": false }],
}
};