Skip to content

Instantly share code, notes, and snippets.

@loucadufault
loucadufault / database.js
Created January 13, 2022 02:23
A simple pattern for opening a mongoose connection to a MongoDB database while registering listeners on the connection and handling the asynchronous result of opening the connection.
import mongoose from "mongoose";
function getConnection(databaseURL, connectionListeners) {
return mongoose.connection;
}
async function openConnection(databaseURL, options) {
await mongoose.connect(databaseURL, options);
}
@loucadufault
loucadufault / pack.ts
Last active January 7, 2022 23:03
Recipe for adding per-user authentication for Google APIs to a Coda pack
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth", // see https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient
tokenUrl: "https://oauth2.googleapis.com/token", // see https://developers.google.com/identity/protocols/oauth2/web-server#exchange-authorization-code
scopes: [
// add any scopes your project requires to access user data from their Google Account