All Projects → hendrysadrak → firestore-store

hendrysadrak / firestore-store

Licence: MIT license
express-session store for Firebase Cloud Firestore

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to firestore-store

nestjs-session
Idiomatic Session Module for NestJS. Built on top of `express-session` 😎
Stars: ✭ 150 (+240.91%)
Mutual labels:  expressjs, express-session
Builderbook
Open source web application to learn JS stack: React, Material-UI, Next.js, Node.js, Express.js, Mongoose, MongoDB database.
Stars: ✭ 3,015 (+6752.27%)
Mutual labels:  expressjs, express-session
mern-boilerplate
React + Express + Webpack + Mongo = MERN Stack Boilerplate
Stars: ✭ 39 (-11.36%)
Mutual labels:  expressjs
docker-node-express-boilerplate
Boilerplate for quickly bootstrapping production-ready RESTful APIs / microservices
Stars: ✭ 113 (+156.82%)
Mutual labels:  expressjs
express-mongodb-crud
Web Application CRUD using Nodejs and Mongodb
Stars: ✭ 87 (+97.73%)
Mutual labels:  expressjs
FireCat
Firestore real time pagination for Android
Stars: ✭ 15 (-65.91%)
Mutual labels:  firestore
ZestX-Frontend
Month-Long Fest Website ZestX with some Awsome UI and Intact Backend. Implemented admin page for user and event management
Stars: ✭ 28 (-36.36%)
Mutual labels:  expressjs
Madara
✍️ A way for people to manage their tasks.
Stars: ✭ 17 (-61.36%)
Mutual labels:  firestore
nodetomic-api
RESTful API Nodejs designed for horizontal scalability with support for cluster, based on Express, MongoDB, Redis, JWT, Socket.io, Passport.
Stars: ✭ 41 (-6.82%)
Mutual labels:  expressjs
GoBarber
💈 Aplicação de agendamento para serviços de beleza, entre provedores e clientes.
Stars: ✭ 84 (+90.91%)
Mutual labels:  expressjs
mern-stack-application
A MERN stack e-commerce website.
Stars: ✭ 45 (+2.27%)
Mutual labels:  expressjs
Trippo-The Travel Guide
Trippo is your smart travel guide - it’s free and works offline, too! You can skim through tours, locations, POIs, city walks, articles and so on. This guide will save you from a serious headache!
Stars: ✭ 28 (-36.36%)
Mutual labels:  firestore
FireShort
A URL Shortener made using React.JS and Google Firestore
Stars: ✭ 29 (-34.09%)
Mutual labels:  firestore
express-mquery
Expose mongoose query API through HTTP request.
Stars: ✭ 37 (-15.91%)
Mutual labels:  expressjs
Blog-Server
The backend Code of Flutter Blog App which is the part of Youtube series. It is developed using the NodeJS/ExpressJs with MongoDB Database
Stars: ✭ 33 (-25%)
Mutual labels:  expressjs
firestore-react
[UNMAINTAINED] Firestore bindings for React components
Stars: ✭ 52 (+18.18%)
Mutual labels:  firestore
hlf1.4-supply-chain
Supply chain proof of concept in Hyperledger Fabric. Network with four companies and a specific chaincode exposed as rest API
Stars: ✭ 30 (-31.82%)
Mutual labels:  expressjs
app
Source code of intencje.pl website and mobile/desktop apps based on Angular, Firebase, and Capacitor.
Stars: ✭ 12 (-72.73%)
Mutual labels:  firestore
react-native-firebase-firestore-crud-example
React Native Firebase Tutorial: Build CRUD Firestore App
Stars: ✭ 24 (-45.45%)
Mutual labels:  firestore
acd
ACD helps you download Adobe Connect Sessions Videos and Audios, download files from FTP server, transfer files using Shift I/O
Stars: ✭ 117 (+165.91%)
Mutual labels:  connect

firestore-store Build Status

Firestore session store for Express.js / Connect.

Source of this library is written in ES6 but commonjs exports are used. If you have any problems or questions let me know in issues.

Installation

firebase-admin is a required peer dependency for firestore-store.

npm install firebase-admin firestore-store --save

Usage with Express.js / Connect

Initialize firebase-admin firestore database.

const admin = require("firebase-admin");

const firebase = admin.initializeApp({
	credential: admin.credential.cert("path/to/serviceAccountCredentials.json"),
	databaseURL: "https://<DATABASE_URL>.firebaseio.com",
});

const database = firebase.firestore();

Pass express-session to firestore-store

const session = require("express-session");
const FirestoreStore = require("firestore-store")(session);

Pass database reference to the FirestoreStore.

express() // or connect
	.use(
		session({
			store: new FirestoreStore({
				database: database,
			}),

			secret: "keyboard cat",
			resave: true,
			saveUninitialized: true,
		})
	);

Usage in Cloud Functions or Cloud Run

When using Firebase Hosting together with Cloud Functions or Cloud Run, cookies are stripped from incoming requests. This would normally prevent the session lookup mechanism from working. However, when using __session as the name, the value will be passed through to the app.

express() // or connect
	.use(
		session({
			store: new FirestoreStore({
				database: database,
			}),

			name: "__session", // ← required for Cloud Functions / Cloud Run
			secret: "keyboard cat",
			resave: true,
			saveUninitialized: true,
		})
	);

Refer to Using Cookies in the Firebase Documentation on Caching

Options

const store = new FirestoreStore(options);

options.database (required)

Firestore reference.

options.collection (default: 'sessions', optional)

Collection name to use for sessions.

options.parser (default: DocParser, optional)

Parser used to save or read session info from session document. If you need custom functionality or want to add more properties you can implement such a parser yourself. Required is to have read and save methods. Check default parser DocParser

Example of a custom parser adding dateModified field:
const parser = {
	read(doc) {
		return JSON.parse(doc.session);
	},

	save(doc) {
		return {
			session: JSON.stringify(doc),
			dateModified: Date.now(),
		};
	},
};

const store = new FirestoreStore({ parser });
Example of a custom parser storing the session in the firestore without stringifying:

#57 (comment)

const parser = {
	read(doc) {
		return doc;
	},

	save(doc) {
		return JSON.parse(JSON.stringify(doc));
	},
};

const store = new FirestoreStore({ parser });

Compatibility

This store implements all the required, recommended and optional methods of the express-session store.

Currently tested with node.js version 10, 12 & 14. Travis is used for running tests https://travis-ci.org/hendrysadrak/firestore-store

Support

If you have any problems or questions let me know in issues.

If you see it as a useful library star it on Github so I know to put more time into supporting it.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].