S
SolidJS5mo ago
ndom91

Passing data from `event.locals` to Frontend

Hey folks, I'm super new to solid/solid start, but I'm trying to implement some authentication and I have my user's session in event.locals and its available in Middleware / BE. But how do I access that event.locals data in the frontend? Having trouble finding anything online.
8 Replies
ndom91
ndom915mo ago
To be clear, using beta.2
Birk Skyum
Birk Skyum5mo ago
Maybe this is how
import { getRequestEvent } from "solid-js/web";

const event = getRequestEvent();
import { getRequestEvent } from "solid-js/web";

const event = getRequestEvent();
ndom91
ndom915mo ago
Ah that did it! Thanks ❤️
Atila
Atila5mo ago
It's important to note that SolidStart's middleware won't intercept client-side nav.
Birk Skyum
Birk Skyum5mo ago
@Atila , what is the implication of that? Does getRequestEvent only give the first event in a potential series?
Atila
Atila5mo ago
if you try to protect a route via a middleware, it won't work for soft-navigation (SPA)
Does getRequestEvent only give the first event in a potential series?
that's a second case where, at the moment, the won't match assets - so it doesn't fire a million times, no need to filter routes out. But it intercepts every flight between client/server - so if you fire a redirect or something, it will fire multiple times. I think for protecting a route, the best case would be to add the logic in a parent route preload function.
protected/
├── private
└── etc...
public/
├── login
└── etc...
protected/
├── private
└── etc...
public/
├── login
└── etc...
so /protected/* can redirect if user is not authorized
Birk Skyum
Birk Skyum5mo ago
Can't really wrap my head around it. I'll have to think about that.
Atila
Atila5mo ago
Particularly, I like Nuxt's approach, where the developer can define route-specific middleware and then do the protection. https://nuxt.com/docs/getting-started/routing#route-middleware I think there's a chance we get there, but I'm not sure how much work is required under the hood to going through middleware on every navigation.
Want results from more Discord servers?
Add your server
More Posts
How does the "You might not need an effect" page from react.dev translate to SolidJS's effects?I feel like they are both the same construct, but since Solid has a fundamentally different way of rDoes solid-element support defining methods on web components?I'm not currently using `solid-element` to define my web component, because I need to define methodsI'd like to see an example of working with a microservices API architectureI think this is the example that is missing from SolidstartSolidStart or Vite + solid-pwa plugin for creating a fast and secure PWA app?I want to create a PWA app using Solid. I am not decided on if I want to use CSR or SSR but I'm leanis Index of Store that is array Signal?I created an array containing several objects based on createStore. When I iterate through this arracaptureStoreUpdates vs reconcileHi! I'm trying to get a stream of immutable object values from a store. The store is frequently updErrors loading Bootstrap SASS in dev-modeI'm migrating a small app from Solid Start 0.3 to 0.5, so I started with a new app and am bringing tsome confusion regarding authentication when accessing third-party APIs in SolidStart.I have some confusion regarding authentication when accessing third-party APIs in SolidStart. Here’sUninitialized signal in JSX but initialized in componentI have a component that is using an xstate machine to handle some state. At the top of the componentunderstanding store setter updatesIn this example: ```typescript import { produce } from "solid-js/store" // without produce setStor