Skip to content

Instantly share code, notes, and snippets.

View philliplakis's full-sized avatar
🏠
Working from home

Phillip Lakis philliplakis

🏠
Working from home
View GitHub Profile
........
router.post("/response", async (req, res, next) => {
if (
!req.body ||
!req.body.id ||
!req.body.rawId ||
!req.body.response ||
!req.body.type ||
req.body.type !== "public-key"
) {
const express = require("express");
const router = express.Router();
const webauthnTools = require("./tools");
const base64url = require("base64url");
const { User } = require("../../model/users");
router.post("/", async (req, res, next) => {
const name = req.user.name;
const username = req.user.email;
@philliplakis
philliplakis / asyncExpress.js
Last active September 4, 2019 03:12
asyncExpress
app.get("/", (req, res) => {
getPerson(req.query.name).then(data => res.json(data));
});
// The Async below:
app.get("/", async (req, res) => {
let data = await getPerson(req.query.name);
res.json(data);
});
@philliplakis
philliplakis / promise_Gfunc.js
Created September 4, 2019 02:58
Gfuction Promise
exports.sub = (pubSubEvent, context) => {
return new Promise(function(resolve, reject) {
processMsg(msgTxt)
.then(result => {
save(result)
.then(data => {
sendPub(data)
.then(() => {
return resolve();
})
@philliplakis
philliplakis / async.js
Last active September 4, 2019 02:57
Promise-V-Async
exports.sub = async (pubSubEvent, context) => {
try {
let result = await processMsg(msgTxt);
let data = await save(result);
await sendPub(data);
} catch (err) {
console.error(err);
return reject(err);
}
};
@philliplakis
philliplakis / index.js
Created September 4, 2019 01:02
rename collection with Mongoose
const mongoose = require("mongoose");
const uri = "DB_URI";
mongoose
.connect(uri, { useNewUrlParser: true })
.then(() => {
console.log("connected");
})
.then(() => {
{
challenge: randomBase64URLBuffer(32),
rp: {
name: "YOUR WEB APP NAME"
},
user: {
id: id,
name: username,
"use strict";
const crypto = require("crypto");
const base64url = require("base64url");
const cbor = require("cbor");
const { Certificate } = require("@fidm/x509");
const iso_3166_1 = require("iso-3166-1");
/**
* U2F Presence constant
*/
NODE_ENV=dev
DB_URL="YOUR_MONGODB_LINK"
const webauthnSchema = new Schema({
active: { default: false, type: Boolean, required: true },
authenticators: [],
id: { type: String, required: false }
});
const userSchema = new Schema({
username: { type: String, required: true },
name: { type: String, required: true },
email: { type: String, required: true },