-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client-only guard() hook #1600
Comments
What is it you're trying to achieve? It isn't clear to me what should happen with that configuration. Because the main purpose of the Closing but let's continue the conversation and let's see if the |
In my case, guard() is necessary to display the authentication page if the user is not authenticated (no token or it has expired). Utilized:
No server-side JavaScript logic for data retrieval, checks, etc. is planned. In guard(), I plan the following:
If the token is valid, another layout and page components are used, within which requests to the REST API are made, and server-side checks are performed to decide which response to return - whether to send requested data, prompt for re-authentication, or something else. |
Correct me if I'm wrong, but I don't think what you want makes sense. Because the very first page the user visits triggers an SSR rendering and you'll need to decide whether to redirect the user already at that point. Thus you need to have your |
I apologize for not paying attention to the topic I initiated myself. To further clarify, the issue is related to a SPA scenario, so |
Indeed, that makes sense. Re-opening. |
@tszyan Correct me if I'm wrong, but isn't handling redirection/guarding on a SPA not Vike's job, but rather the frontend framework (client code) you're using? For me on SolidJS, I'm personally using a combination of:
Here's some sample code: |
Certainly, you're right that such functionality can be implemented independently on the client side using a frontend framework. However, considering that the guard() functionality exists for these purposes, albeit currently only on the server side, it would be logical to extend its implementation to the client side within Vike. Given Vike's support for both SSR and SPA, it would enhance consistency to have the ability to implement this functionality uniformly across both models. |
I agree, this could be very useful on the client as well, since routing can be done on the client it makes sense. I had the same concern and yesterday I opened a discussion. I'm still reading through the documentation, doing some experiments and trying to understand how the framework works though. |
I can't see a concrete use case for this. What's your architecture that explains your wish to call |
https://vike.dev/guard now contains information about where and when It may (or may not) address the issues of OP, let me know whether it does 👀 |
@brillout Thank you. However, I still see issues related to SPA both in the documentation and in how Vike works in this mode (according to the documentation, as I haven't personally checked yet). In particular, it is stated that both Despite the popularity of SSR, the demand for SPA applications is still high. In order for SPA developers not to have to experiment with what works and how, and for the behavior of the Vike framework to be predictable in such scenarios, it is better to separate the description of configuration and how Vike works in different modes, especially SPA and SSR, in the documentation. |
@tszyan The docs were incorrect and I updated them: b675e81. I believe the use cases are covered by Vike's design, as well as now documented (atlhough there is room for improvement as you rightfully suggest). Let me know if you still believe something's missing from either the docs or Vike's design — supporting client-centric apps is very much a priority. If someone's company is up for it we're looking for sponsors, as it makes a massiv difference to the project. |
Description
It appears that the guard() hook is not functioning correctly when used with the following configuration:
No additional logic is implemented within the guard, just:
Upon the initial page load or reloading with F5, the page loads without the guard hook being triggered.
It's the same behavior observed with Solid and React batijs scaffolds.
The text was updated successfully, but these errors were encountered: