Fork me on GitHub
#re-frame
<
2023-06-27
>
Eitan04:06:05

Hello, I am making a project that uses shadow-cljs, reitit, and firebase. I am now doing the routing for my navigation, and I wanted to see if what I am doing makes sense. I was thinking of authenticating my user before running the routes. If I do have a valid user, I will run the controllers for that route. If not, I will send them to the home page Does anyone have any comments about this? Any suggestions?

hifumi12305:06:07

Define "running the routes." Do all routes require authorization? If so, then you can simply not call reitit.frontend.easy/start! until you've authenticated a user

hifumi12305:06:50

If some routes are public then you can conditionally call reitit.frontend.controllers/apply-controllers when the URL is changing. The easiest way to implement is to first register a :route/navigated event that applies controllers and is dispatched whenever routes change, then add an interceptor to this event that checks authentication status before the event handler runs, and provide some data indicating whether the user is authenticated or not.

p-himik07:06:51

I prefer to separate authentication and UI routing. When a user makes any request to the server, the server checks for a session, for all non-public routes. If it's there - proceed as normal. If it's not - redirect to /login with a breadcrumb that will let the server proceed as normal after the user provides the right credentials. Re-frame is not involved in the process at all.

Ben Lieberman20:06:41

So maybe the answer is just "don't use Strict Mode" but I started doing so and I noticed that it resets my app-db 😑 I'm guessing this happens bc of that double render. Is there a way around that?

hifumi12320:06:07

strict mode should not interfere with this — assuming you’re using shadow-cljs, i would look at your after-load hooks, I guarantee one of them is dispatching some event that is not returning a copy of your app-db

hifumi12320:06:57

IIRC reagent by default uses strict mode (at least when i used re-frame + react 17 the react devtools always showed i was using strict mode), so i dont think strict mode is a problem at all

Ben Lieberman20:06:42

Not according to react devtools at least, the little warning icon appears next to my root element saying it's not in strict mode

Ben Lieberman20:06:56

(If I turn it off myself that is)

Ben Lieberman20:06:03

I'll take a look at my hooks though, thanks

Eitan20:06:21

Hello everyone, I am using firebase in my project and I am doing my unit tests with karma. In one of my tests I want to add a user, which requires using the admin auth sdk. However, karma runs the tests in a browser environment but the auth sdk must be used in a node.js environment. A solution I was thinking of was to run the test in a separate file with a node.js environment. What would you guys recommend?

p-himik20:06:22

This seems to be better suited for #C03RZGPG3, no? Since it seems to be irrelevant not only to re-frame (where you're asking this question) but also to CLJS.

Eitan21:06:37

I forgot to mention that I am testing an event that reads from the database. I thought that someone might have already encountered this type of scenario.

Eitan21:06:34

Sorry about how I phrased my question. I’ll make them more relevant to the channel.