Fix bugs from refactor!
This commit is contained in:
@@ -18,5 +18,5 @@ indent_size = 4
|
|||||||
|
|
||||||
# Matches the exact files either package.json or .travis.yml
|
# Matches the exact files either package.json or .travis.yml
|
||||||
[{package.json,serverless.yml}]
|
[{package.json,serverless.yml}]
|
||||||
indent_style = space
|
indent_style = tab
|
||||||
indent_size = 2
|
indent_size = 4
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const ExtractJWT = require(`passport-jwt`).ExtractJwt;
|
|||||||
const { users } = require(`../models`);
|
const { users } = require(`../models`);
|
||||||
|
|
||||||
module.exports = (passport) => {
|
module.exports = (passport) => {
|
||||||
|
|
||||||
const options = {};
|
const options = {};
|
||||||
options.jwtFromRequest = ExtractJWT.fromAuthHeaderAsBearerToken();
|
options.jwtFromRequest = ExtractJWT.fromAuthHeaderAsBearerToken();
|
||||||
options.secretOrKey = process.env.tokenSecret;
|
options.secretOrKey = process.env.tokenSecret;
|
||||||
@@ -24,6 +23,6 @@ module.exports = (passport) => {
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
return done(null, false);
|
return done(null, false);
|
||||||
}
|
}
|
||||||
return done(null, user);
|
return done(null, users.convertToPublicFormat(user));
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const register = async (req, res, next) => {
|
|||||||
return next(error, null);
|
return next(error, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = jwt.sign(user, process.env.tokenSecret, {
|
const token = jwt.sign(users.convertToPublicFormat(user), process.env.tokenSecret, {
|
||||||
expiresIn: 604800 // 1 week
|
expiresIn: 604800 // 1 week
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ const login = async (req, res, next) => {
|
|||||||
return res.status(401).send({ error: `Authentication failed. Wrong password.` });
|
return res.status(401).send({ error: `Authentication failed. Wrong password.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = jwt.sign(user, process.env.tokenSecret, {
|
const token = jwt.sign(users.convertToPublicFormat(user), process.env.tokenSecret, {
|
||||||
expiresIn: 604800 // 1 week
|
expiresIn: 604800 // 1 week
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const register = async (user = {}) => {
|
|||||||
{
|
{
|
||||||
hk: user.email,
|
hk: user.email,
|
||||||
password: user.password,
|
password: user.password,
|
||||||
}).promise();
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,12 +51,9 @@ const getByEmail = async (email) => {
|
|||||||
throw new Error(`"${email}" is not a valid email address`);
|
throw new Error(`"${email}" is not a valid email address`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await db.getByKey(email).promise();
|
let user = await db.getByKey(email);
|
||||||
|
|
||||||
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
||||||
if (user) {
|
|
||||||
user = convertToPublicFormat(user);
|
|
||||||
}
|
|
||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,12 +67,9 @@ const getById = async (id) => {
|
|||||||
throw new Error(`"id" is required`);
|
throw new Error(`"id" is required`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await db.getById(`user`, id).promise();
|
let user = await db.getById(`user`, id);
|
||||||
|
|
||||||
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
||||||
if (user) {
|
|
||||||
user = convertToPublicFormat(user);
|
|
||||||
}
|
|
||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "forgetmenot-api",
|
"name": "forgetmenot-api",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"passport": "^0.4.1",
|
"passport": "^0.4.1",
|
||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
"shortid": "^2.2.15"
|
"shortid": "^2.2.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.12.1"
|
"eslint": "^7.12.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "eslint --ignore-path ../.gitignore .",
|
"pretest": "eslint --ignore-path ../.gitignore .",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ component: express
|
|||||||
name: api
|
name: api
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
# Express application source code.
|
# Express application source code.
|
||||||
src: ./
|
src: ./
|
||||||
# Permissions required for the AWS Lambda function to interact with other resources
|
# Permissions required for the AWS Lambda function to interact with other resources
|
||||||
roleName: ${output:permissions.name}
|
roleName: ${output:permissions.name}
|
||||||
# Enable this when you want to set a custom domain.
|
# Enable this when you want to set a custom domain.
|
||||||
# domain: api.${env:domain}
|
# domain: api.${env:domain}
|
||||||
# Environment variables
|
# Environment variables
|
||||||
env:
|
env:
|
||||||
# AWS DynamoDB Table name. Needed for the code to access it.
|
# AWS DynamoDB Table name. Needed for the code to access it.
|
||||||
db: ${output:database.name}
|
db: ${output:database.name}
|
||||||
# AWS DynamoDB Table Index name. Needed for the code to access it.
|
# AWS DynamoDB Table Index name. Needed for the code to access it.
|
||||||
dbIndex1: ${output:database.indexes.gsi1.name}
|
dbIndex1: ${output:database.indexes.gsi1.name}
|
||||||
# A secret token to sign the JWT tokens with.
|
# A secret token to sign the JWT tokens with.
|
||||||
tokenSecret: ${env:tokenSecret} # Change to secret via environment variable: ${env:tokenSecret}
|
tokenSecret: ${env:tokenSecret} # Change to secret via environment variable: ${env:tokenSecret}
|
||||||
|
|||||||
@@ -2,29 +2,29 @@ component: aws-dynamodb
|
|||||||
name: database
|
name: database
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
name: ${name}-${stage}
|
name: ${name}-${stage}
|
||||||
region: us-east-1
|
region: us-east-1
|
||||||
# Don't delete the Database Table if "serverless remove" is run
|
# Don't delete the Database Table if "serverless remove" is run
|
||||||
deletionPolicy: retain
|
deletionPolicy: retain
|
||||||
# Simple, single-table design
|
# Simple, single-table design
|
||||||
attributeDefinitions:
|
attributeDefinitions:
|
||||||
- AttributeName: hk
|
- AttributeName: hk
|
||||||
AttributeType: S
|
AttributeType: S
|
||||||
- AttributeName: sk
|
- AttributeName: sk
|
||||||
AttributeType: S
|
AttributeType: S
|
||||||
- AttributeName: sk2
|
|
||||||
AttributeType: S
|
|
||||||
keySchema:
|
|
||||||
- AttributeName: hk
|
|
||||||
KeyType: HASH
|
|
||||||
- AttributeName: sk
|
|
||||||
KeyType: RANGE
|
|
||||||
globalSecondaryIndexes:
|
|
||||||
- IndexName: gsi1
|
|
||||||
KeySchema:
|
|
||||||
- AttributeName: sk2
|
- AttributeName: sk2
|
||||||
|
AttributeType: S
|
||||||
|
keySchema:
|
||||||
|
- AttributeName: hk
|
||||||
KeyType: HASH
|
KeyType: HASH
|
||||||
- AttributeName: sk
|
- AttributeName: sk
|
||||||
KeyType: RANGE
|
KeyType: RANGE
|
||||||
Projection:
|
globalSecondaryIndexes:
|
||||||
ProjectionType: ALL
|
- IndexName: gsi1
|
||||||
|
KeySchema:
|
||||||
|
- AttributeName: sk2
|
||||||
|
KeyType: HASH
|
||||||
|
- AttributeName: sk
|
||||||
|
KeyType: RANGE
|
||||||
|
Projection:
|
||||||
|
ProjectionType: ALL
|
||||||
|
|||||||
@@ -2,27 +2,27 @@ component: aws-iam-role
|
|||||||
name: permissions
|
name: permissions
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
name: ${name}-${stage}
|
name: ${name}-${stage}
|
||||||
region: us-east-1
|
region: us-east-1
|
||||||
service: lambda.amazonaws.com
|
service: lambda.amazonaws.com
|
||||||
policy:
|
policy:
|
||||||
# AWS Lambda function containing Express Logs and Assume Role access
|
# AWS Lambda function containing Express Logs and Assume Role access
|
||||||
- Effect: Allow
|
- Effect: Allow
|
||||||
Action:
|
Action:
|
||||||
- sts:AssumeRole
|
- sts:AssumeRole
|
||||||
- logs:CreateLogGroup
|
- logs:CreateLogGroup
|
||||||
- logs:CreateLogStream
|
- logs:CreateLogStream
|
||||||
- logs:PutLogEvents
|
- logs:PutLogEvents
|
||||||
Resource: "*"
|
Resource: "*"
|
||||||
# AWS DynamoDB Table access
|
# AWS DynamoDB Table access
|
||||||
- Effect: Allow
|
- Effect: Allow
|
||||||
Action:
|
Action:
|
||||||
- dynamodb:DescribeTable
|
- dynamodb:DescribeTable
|
||||||
- dynamodb:Query
|
- dynamodb:Query
|
||||||
- dynamodb:GetItem
|
- dynamodb:GetItem
|
||||||
- dynamodb:PutItem
|
- dynamodb:PutItem
|
||||||
- dynamodb:UpdateItem
|
- dynamodb:UpdateItem
|
||||||
- dynamodb:DeleteItem
|
- dynamodb:DeleteItem
|
||||||
Resource:
|
Resource:
|
||||||
- ${output:database.arn}
|
- ${output:database.arn}
|
||||||
- ${output:database.arn}/index/*
|
- ${output:database.arn}/index/*
|
||||||
|
|||||||
@@ -1,37 +1,37 @@
|
|||||||
{
|
{
|
||||||
"name": "serverless-fullstack-app-website",
|
"name": "serverless-fullstack-app-website",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@testing-library/react": "^9.3.2",
|
"@testing-library/react": "^9.3.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-scripts": "3.4.3",
|
"react-scripts": "3.4.3",
|
||||||
"js-cookie": "^2.2.1",
|
"js-cookie": "^2.2.1",
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"react-router-dom": "^5.1.2"
|
"react-router-dom": "^5.1.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "react-app"
|
"extends": "react-app"
|
||||||
},
|
},
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
"production": [
|
"production": [
|
||||||
">0.2%",
|
">0.2%",
|
||||||
"not dead",
|
"not dead",
|
||||||
"not op_mini all"
|
"not op_mini all"
|
||||||
],
|
],
|
||||||
"development": [
|
"development": [
|
||||||
"last 1 chrome version",
|
"last 1 chrome version",
|
||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ component: website
|
|||||||
name: site
|
name: site
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
# React application. "hook" runs before deployment to build the source code. "dist" is the built artifact directory which is uploaded.
|
# React application. "hook" runs before deployment to build the source code. "dist" is the built artifact directory which is uploaded.
|
||||||
src:
|
src:
|
||||||
src: ./
|
src: ./
|
||||||
hook: npm run build
|
hook: npm run build
|
||||||
dist: build
|
dist: build
|
||||||
# Enable this when you want to set a custom domain.
|
# Enable this when you want to set a custom domain.
|
||||||
# domain: ${env:domain}
|
# domain: ${env:domain}
|
||||||
|
|||||||
Reference in New Issue
Block a user