Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- migrate:up
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE,
hash_password VARCHAR(255),
created_at TIMESTAMP DEFAULT NOW() NOT NULL,
updated_at TIMESTAMP DEFAULT NOW() NOT NULL
);

CREATE INDEX idx_email ON users (email);

-- migrate:down
DROP TABLE users;
16 changes: 16 additions & 0 deletions capstone/backend/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// codes in here are inspired from: https://dev.to/remix-run-br/type-safe-environment-variables-on-both-client-and-server-with-remix-54l5
// It's a type-safe way of accessing environment variables.
// App will not run if process.env doesn't meet the zod schema

import { z } from "zod";

const environmentSchema = z.object({
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
JWT_SECRET: z.string().min(1),
});

const environment = environmentSchema.parse(process.env);

export { environment };
11 changes: 11 additions & 0 deletions capstone/backend/middlewares/autenticated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tokenValidator from "../services/tokenValidator.js";

export default function authenticated(req, res, next) {
const { isValid, ...props } = tokenValidator(req.cookies.token);

if (isValid) {
next();
} else {
return res.status(401).send({ error: props.error });
}
}
151 changes: 151 additions & 0 deletions capstone/backend/package-lock.json

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

3 changes: 3 additions & 0 deletions capstone/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"camelcase-keys": "^9.0.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dbmate": "^2.6.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.2",
"morgan": "^1.10.0",
"postgres": "^3.3.5",
"zod": "^3.22.2"
Expand Down
25 changes: 25 additions & 0 deletions capstone/backend/requests/auth.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
POST http://localhost:8081/api/auth/sign-up
Content-Type: application/json

{
"email": "johndoe3@gmail.com",
"password": "abcdefghh123"
}

###

POST http://localhost:8081/api/auth/sign-in
Content-Type: application/json

{
"email": "johndoe3@gmail.com",
"password": "abcdefghh123"
}

###

POST http://localhost:8081/api/auth/sign-out

###

GET http://localhost:8081/api/auth/verify
Loading