Skip to content

Instantly share code, notes, and snippets.

View danielkhan's full-sized avatar

Daniel Khan danielkhan

  • Sentry
  • Linz / Austria
  • X @dkhan
View GitHub Profile
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
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 });
}
const mongoose = require('mongoose');
const ContactSchema = mongoose.Schema({
user_id: {
type: mongoose.Schema.ObjectId,
required: true,
},
firstname: {
type: String,
required: true,
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) => {
module.exports = {
"extends": "airbnb-base",
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
"no-underscore-dangle": ["error", { "allow": ["_id"] }],
"no-param-reassign": ["error", { "props": false }],
}
};
/**
* @swagger
* /users/register:
* post:
* parameters:
* - in: body
* name: user
* description: The user to create.
* schema:
* $ref: "#/definitions/User"
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);
// /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;
module.exports = {
extends: "airbnb-base",
rules: {
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }] ,
"no-param-reassign": ["error", { "props": false }],
},
env: {
node: true,
mocha: true
}
module.exports = {
"extends": "airbnb-base",
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
"no-param-reassign": ["error", { "props": false }],
}
};