Comments (5)
Happy new year 🙂
You can do this in "app space" by modifying the default wrap-signed-in
middleware to do a DB query:
(defn wrap-signed-in [handler]
(fn [{:keys [session biff/db] :as ctx}
user (some->> (:uid session) (biff/lookup db))]
(if user
(handler (assoc ctx :user user))
{:status 303
:headers {"location" "/signin?error=not-signed-in"}
:session (dissoc session :uid)})))
As for whether this should be the default implementation: not sure. Assuming your app has a sign-out button somewhere easily accessible, then you can also just click on that after doing rm -r storage
right? I believe that'll work in the default example app anyway--the page will still load and the sign-out button will be visible, you just won't see any values in the default crud form because there's no user document.
I think I'd prefer to leave it at that rather than modifying the default middleware to do a DB query on every (authenticated) request. Those who want this behavior can make the decision to do that if they want. As it is, Biff's default middleware stack doesn't do any DB queries (I'm pretty sure?) so I wouldn't be able to add this functionality without introducing a new query somewhere.
from biff.
I hear what you're saying. I still think the better default is to hit the db on every request though.
I've come to use this middleware instead:
(defn wrap-require-user [handler]
"Ensures the user is logged in and that :user is associated
with (xt/entity uid). If your handler or middleware requires :user,
use it explicitly."
(fn [{:keys [session biff/db] :as ctx}]
(if-not (some? (:uid session))
{:status 303
:headers {"location" "/signin?error=not-signed-in"}}
(if-let [user (or (:user ctx)
(xt/entity db (:uid session)))]
(handler (assoc ctx :user user))
{:status 303
:headers {"location" "/signin?error=not-signed-in"}}))))
from biff.
Btw feel free to close :^), or I can pr if u like the middleware
from biff.
I hear what you're saying. I still think the better default is to hit the db on every request though.
I still think it's definitely better not to do that by default 😉 .
Do you want to stick this middleware in a gist or write up a short blog post or something though? I'd be happy to add a link for it in the content library.
from biff.
I think it's fine that it lives here for now :)
from biff.
Related Issues (20)
- Unable to create new project HOT 2
- Get started instructions not working? HOT 1
- `secret.env` values are inconsistent in dev/prod when using quotes HOT 10
- Add docs for fixing UnsatisfiedLinkError
- Update docs to use `bb` folder instead of `tasks` HOT 1
- Sometimes auth plugin blocks on signin HOT 1
- Sometimes the first bb deploy doesn't work without -f HOT 3
- (Website) Hero section is fixed on mobile and obstructs view when scrolling HOT 2
- Error while executing task: css HOT 3
- Signin via new email yields Sign-up-like email but doesn't create session
- How to use Biff with datomic? Any example? HOT 3
- [feature suggestion] biff libraries repository HOT 2
- [Docs] Broken links on Should you use Biff article HOT 1
- Can't start `bb dev` on a fresh install HOT 7
- Biff example site does not load: java.lang.ArithmeticException: long overflow HOT 2
- `install-tailwind` fetches the ARM binary on a x86 Mac HOT 2
- Is it possible to keep assets files in modules? HOT 1
- Document writing a test that roundtrips to xtdb? HOT 2
- Execution error (NullPointerException) at com.biffweb.tasks/dev (tasks.clj:290). HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from biff.