Code Monkey home page Code Monkey logo

connect-session-firestore's People

Contributors

benweier avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

connect-session-firestore's Issues

Error trying to save a Session object

Hi there! I'm trying to get this up and running, but I must have made a mistake somewhere.

With my current setup, I am getting this error:

Error: Argument "data" is not a valid Document. Couldn't serialize object of type "Session". Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the 'new' operator).

The error occurs when this method is called; session is a Session instance.

Logging it out, I received:

Session {
  cookie:
   { path: '/',
     _expires: null,
     originalMaxAge: null,
     httpOnly: true } }

I followed the express instructions from the README. Here are some relevant versions and code:

"connect-session-firestore": "1.0.0",
"express": "4.16.3",
"express-session": "1.15.6",
"firebase-admin": "5.12.0",
const session = require('express-session');
const FirestoreStore = require('connect-session-firestore')(session);

// This is the return value from `firebase.initializeApp()`
const firebaseAdmin = require('../utils/firebase-admin');

const router = express.Router();

router.use(session({
  store: new FirestoreStore({
    database: firebaseAdmin.firestore()
  }),
  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true
}));

I'm new to Firebase, but it's looking like the express-session is supposed to be passing the session instance.

Is there something I need to configure to enable Firebase to serialize session objects?

Thanks for reading!


Update: The problem seems to be two levels deep. Not only is session an invalid object for Firestore, but the session.cookie is, too.

As a super hacky workaround, I am doing this:

    let sessionObj = {
      cookie: {}
    };

    for (let key in session) {
      const sessionValue = session[key];
      if (key === 'cookie') {
        const naiveCookie = sessionValue.toJSON();
        for (let cookieKey in naiveCookie) {
          if (naiveCookie[cookieKey]) {
            sessionObj.cookie[cookieKey] = naiveCookie[cookieKey];
          }
        }
      } else if (isPrimitive(sessionValue)) {
        sessionObj[key] = sessionValue;
      } else if (sessionValue && sessionValue.constructor === Object) {
        sessionObj[key] = sessionValue;
      }
    }

    const data = {
      expires: expires,
      session: sessionObj,
      type: 'connect-session'
    };

It is far from perfect, and embarrassingly hacky, but it has (for the time being) unblocked me. I'm very curious to learn more about how folks are getting the session object into Firebase without resorting to such crazy hacks!

Application hangs?

I've implemented your connect-session-firbase and it works great but whenever I try and use this one the browser just hangs when I try to connect to the application?

Also small mistake in the docs for both repos - you're missing a comma after the secret value of 'keyboard cat'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.