Currently, layout.js has an onload callback which triggers the app model's initialize effect. The initialize effect calls pouchdb's getSession(), which queries couchdb's _session endpoint to validate the cookie. If the user is not logged in, the app model's initialize effect does a hard redirect to /login. If the user is logged in, it sets the user data via the user model's set reducer, then triggers the convos model's fetch effect to get all the messages as a logged in user.
This works pretty well, but it doesn't feel right to have this done in the onload callback inside a big effect.
A more traditional approach would have some sort of validation happening in the router, but I can't quite get a good workflow going. The only thing I can think of that would truly work is to do the checking prior to app.start(). If the user's not logged in, redirect them to /login, otherwise pass their initial state (we'd have to wrap the model in a function to accept initial state). But having a server side call before render seems bad.
Currently,
layout.js
has anonload
callback which triggers theapp
model'sinitialize
effect. Theinitialize
effect calls pouchdb'sgetSession()
, which queries couchdb's_session
endpoint to validate the cookie. If the user is not logged in, theapp
model'sinitialize
effect does a hard redirect to/login
. If the user is logged in, it sets the user data via theuser
model'sset
reducer, then triggers theconvos
model'sfetch
effect to get all the messages as a logged in user.This works pretty well, but it doesn't feel right to have this done in the onload callback inside a big effect.
A more traditional approach would have some sort of validation happening in the router, but I can't quite get a good workflow going. The only thing I can think of that would truly work is to do the checking prior to
app.start()
. If the user's not logged in, redirect them to/login
, otherwise pass their initial state (we'd have to wrap the model in a function to accept initial state). But having a server side call before render seems bad.