This file contains hidden or 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
{ | |
"openapi": "3.0.0", | |
"paths": { | |
"/api/orders/orders/latest": { | |
"get": { | |
"operationId": "getLastPurchasedOrder", | |
"summary": "Get last purchase order for a user", | |
"description": "Get last purchased order by user ID", | |
"parameters": [ | |
{ |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<script defer src="https://cdn.optimizely.com/js/16180790160.js"></script> | |
<title data-rh="true"> | |
Unlearning. My last post was about unlearning the… | by Kheoh Yee Wei | | |
Jan, 2021 | Medium | |
</title> | |
<meta data-rh="true" charset="utf-8" /> | |
<meta |
This file contains hidden or 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 argon2 = require("argon2-ffi").argon2i; | |
const crypto = require("crypto"); | |
const util = require("util"); | |
const createError = require("http-errors"); | |
const randomBytes = util.promisify(crypto.randomBytes); | |
async function hashPassword(password) { | |
try { | |
return randomBytes(32).then((salt) => argon2.hash(password, salt)); | |
} catch (e) { |
This file contains hidden or 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 express = require("express"); | |
const cors = require("cors"); | |
const createError = require("http-errors"); | |
const app = express(); | |
const isProduction = app.get("env") === "production"; | |
if (isProduction) { | |
app.set("trust proxy", 1); |
This file contains hidden or 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
import { h, Component } from "preact"; | |
class Otp extends Component { | |
// onKeyDown event is triggered BEFORE onKeyPress event | |
keyDown = e => { | |
const { keyCode } = e; | |
const wasNonNumericEntered = !(keyCode >= 48 && keyCode <= 57) && !(keyCode >= 96 && keyCode <= 105); | |
// don't do anything if entered non-numeric values | |
if (wasNonNumericEntered) e.preventDefault(); | |
This file contains hidden or 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 bcrypt = require("bcryptjs"); | |
router.post("/register", async (req, res) => { | |
const { fullName, email, password } = req.body; | |
const hashedPassword = await bcrypt.hash(password, 8); | |
const query = `INSERT INTO account(fullname, email, password) VALUES ($1, $2, $3) RETURNING user_id, fullname, email`; | |
const values = [fullName, email, hashedPassword]; | |
This file contains hidden or 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
// app.js | |
const express = require("express"); | |
const session = require("express-session"); | |
const redisStore = require("connect-redis")(session); | |
const redis = require("redis"); | |
const redisClient = redis.createClient(); | |
const app = express(); | |
const isProduction = app.get("env") === "production"; |
This file contains hidden or 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 Auth = require("../lib/auth"); | |
const multer = require("multer"); | |
const upload = multer(); | |
const asyncHandler = require("express-async-handler"); | |
router.post("/signin", upload.none(), asyncHandler(async (req, res, next) => { | |
const { email, plainTextPassword } = req.body; | |
// get the hashed password associated to the email entered by user | |
const query = `SELECT password FROM account WHERE email=($1)`; |
This file contains hidden or 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
// import our wrapper auth.js | |
const Auth = require("../lib/auth"); | |
const multer = require("multer"); | |
// we gonna use upload.none() rather than body-parser to access 'req.body' | |
// I don't recommed inserting body-parser middleware to your 'app'. Specify it per route. | |
const upload = multer(); | |
const asyncHandler = require("express-async-handler"); | |
router.post("/register", upload.none(), asyncHandler(async (req, res, next) => { | |
const { fullName, email, password } = req.body; |
This file contains hidden or 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
function generateToken({ user_id, fullname, email }) { | |
const data = { | |
sub: user_id, | |
name: fullname, | |
}; | |
return jwt.sign(data, SESSION_SECRET_KEY, { | |
expiresIn: "7d" | |
}); |
NewerOlder