This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
const ContactSchema = mongoose.Schema({ | |
user_id: { | |
type: mongoose.Schema.ObjectId, | |
required: true, | |
}, | |
firstname: { | |
type: String, | |
required: true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
"extends": "airbnb-base", | |
"rules": { | |
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }], | |
"no-underscore-dangle": ["error", { "allow": ["_id"] }], | |
"no-param-reassign": ["error", { "props": false }], | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @swagger | |
* /users/register: | |
* post: | |
* parameters: | |
* - in: body | |
* name: user | |
* description: The user to create. | |
* schema: | |
* $ref: "#/definitions/User" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
extends: "airbnb-base", | |
rules: { | |
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }] , | |
"no-param-reassign": ["error", { "props": false }], | |
}, | |
env: { | |
node: true, | |
mocha: true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
"extends": "airbnb-base", | |
"rules": { | |
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }], | |
"no-param-reassign": ["error", { "props": false }], | |
} | |
}; |