Skip to content

Commit

Permalink
[SLUG] Transferring changes from Slug as of 2023-01-18 10:03:48 +0000.
Browse files Browse the repository at this point in the history
  • Loading branch information
leoht committed Jan 18, 2023
1 parent bb871b1 commit 0c9873b
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 123 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified api/.DS_Store
Binary file not shown.
9 changes: 7 additions & 2 deletions api/models/token_generator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const JWT = require("jsonwebtoken");
const options = {expiresIn: "10m"};
const secret = process.env.JWT_SECRET;

class TokenGenerator {
static jsonwebtoken(user_id) {
return JWT.sign({user_id: user_id, iat: Date.now()}, secret, options);
return JWT.sign({
user_id: user_id,
iat: Math.floor(Date.now() / 1000),

// Set the JWT token to expire in 10 minutes
exp: Math.floor(Date.now() / 1000) + (10 * 60)
}, secret);
}
}

Expand Down
139 changes: 21 additions & 118 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"express-session": "^1.17.2",
"hbs": "^4.1.0",
"http-errors": "~1.6.3",
"jsonwebtoken": "^8.5.1",
"jsonwebtoken": "^9.0.0",
"method-override": "^3.0.0",
"mongodb": "^3.4.1",
"mongoose": "^5.8.11",
Expand Down
Binary file modified api/spec/.DS_Store
Binary file not shown.
12 changes: 10 additions & 2 deletions api/spec/controllers/posts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ const request = require("supertest");
require("../mongodb_helper");
const Post = require('../../models/post');
const User = require('../../models/user');
const TokenGenerator = require('../../models/token_generator');
const JWT = require("jsonwebtoken");
const secret = process.env.JWT_SECRET;

let token;

describe("/posts", () => {
beforeAll( async () => {
const user = new User({email: "[email protected]", password: "12345678"});
await user.save();
token = TokenGenerator.jsonwebtoken(user.id);

token = JWT.sign({
user_id: user.id,
// Backdate this token of 5 minutes
iat: Math.floor(Date.now() / 1000) - (5 * 60),
// Set the JWT token to expire in 10 minutes
exp: Math.floor(Date.now() / 1000) + (10 * 60)
}, secret);
});

beforeEach( async () => {
Expand Down
Binary file modified frontend/cypress/videos/making_a_post.cy.js.mp4
Binary file not shown.
Binary file modified frontend/cypress/videos/signing_in.cy.js.mp4
Binary file not shown.
Binary file modified frontend/cypress/videos/signing_up.cy.js.mp4
Binary file not shown.
Binary file removed public/.DS_Store
Binary file not shown.

0 comments on commit 0c9873b

Please sign in to comment.