Je Suis Un Ami
Explore posts from serversHow to Execute Server Action on Each Route Visit?
I have a home component (code in comments)
In summary, what this component does is it calls a server action to check if the user is authenticated. If the user is authenticated, it redirects the user to the dashboard route. Otherwise, it redirects the user to the login route.
Now, here's my question. What I want to do is perform this verification every time the home route is visited (even from a client-side redirect). From my logs however, it doesn't look like the server action is being called in subsequent visits to this route (i.e. after the account setup process is complete. The reason I know this is because "Executing checks to determine redirect" is being printed on my console. But, none of the other logs that would be printed if the action completed are. In other words
authenticatedUser.result
is always falsy. How would I go about doing what I am trying to do? Is there a different approach I should be taking to accomplish what I am trying to do?
Thanks. Like I said, component code is in the first comment of this thread.16 replies
Server Actions and Cookies sending error: Cannot set headers after they are sent to the clien
Maybe I am misunderstanding something here. I am following the docs for Actions. Basically, what this component is supposed to do is check for the pressence of a session cookie. And, if the user is authenticated, redirects the client to the dashboard page. And if not, it redirects the client to the login page.
I included the action definition in the comments.
29 replies
Context Not Being Defined
I am running into a problem where the
AuthContext
isn't being defined in m app.
Here's my App component:
For convenience, here is my <mAIN />
component:
Essentially, the error being thrown is Uncaught TypeError: Cannot read properties of null
, referring to the auth check being done by the authenticated()
signal, defined in the AuthContext
context.
Here is the slimmed down version of my AuthContext
:
In my logs, I know that AuthContext
is not being defined because the print statement defined in it is never shown.
How would I fix this?2 replies
Saving Results of routeData() into a Context
What is the proper way to save the results of routeData() into a context? So, here's my setup.
Here's my root.
And, in my route component, I have it like this:
According to my logs, data is present in both the routeData() and when the component initially renders. However, it doesn't seem like it is ever put into the context (as in, it's saying it is undefined on my UI). How would I go about this?
2 replies
Creating an Observable from a store.
Is there a way I can create an observable from a store?
Essentially, what I want to do this:
Or, something like that at least.
This fails because the
observable()
function accepts an Accessor, which pretty much is only signals. Is there a way I can make it work with stores as well?4 replies