Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Commit 75682f0

Browse files
committed
adding auth
1 parent 7cf6991 commit 75682f0

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

course-02/exercises/udacity-c2-restapi/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ POSTGRES_HOST=database-1.cl5acgthoh69.eu-west-2.rds.amazonaws.com
55
POSTGRES_DIALECT=postgres
66
AWS_REGION=eu-west-2
77
AWS_PROFILE=default
8-
AWS_MEDIA_BUCKET=324941539183-c2-bucket-dev
8+
AWS_MEDIA_BUCKET=324941539183-c2-bucket-dev
9+
JWT_SECRET=helloworld

course-02/exercises/udacity-c2-restapi/package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

course-02/exercises/udacity-c2-restapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"author": "Gabriel Ruttner",
1717
"license": "ISC",
1818
"dependencies": {
19-
"@types/bcrypt": "^3.0.0",
2019
"@types/jsonwebtoken": "^8.3.2",
2120
"aws-sdk": "^2.492.0",
2221
"bcrypt": "^5.0.0",
@@ -31,6 +30,7 @@
3130
"sequelize-typescript": "^0.6.11"
3231
},
3332
"devDependencies": {
33+
"@types/bcrypt": "^3.0.0",
3434
"@types/bluebird": "^3.5.33",
3535
"@types/express": "^4.17.9",
3636
"@types/node": "^11.15.42",

course-02/exercises/udacity-c2-restapi/src/config/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ export const config = {
1515
"database": "udagram_prod",
1616
"host": "",
1717
"dialect": "postgres"
18+
},
19+
"jwt": {
20+
"secret": process.env.JWT_SECRET
1821
}
1922
}

course-02/exercises/udacity-c2-restapi/src/controllers/v0/users/routes/auth.router.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ const router: Router = Router();
1212

1313
async function generatePassword(plainTextPassword: string): Promise<string> {
1414
//@TODO Use Bcrypt to Generated Salted Hashed Passwords
15-
return "NotYetImplemented"
15+
const saltRounds = 10;
16+
const salt = await bcrypt.genSalt(saltRounds);
17+
const hash = await bcrypt.hash(plainTextPassword, salt);
18+
return hash
1619
}
1720

1821
async function comparePasswords(plainTextPassword: string, hash: string): Promise<boolean> {
1922
//@TODO Use Bcrypt to Compare your password to your Salted Hashed Password
20-
return true
23+
const compare = await bcrypt.compare(plainTextPassword, hash);
24+
return compare
2125
}
2226

2327
function generateJWT(user: User): string {

0 commit comments

Comments
 (0)