Comments (5)
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 guard()
hook is to protect unauthorized access, e.g. to protect an admin page from regular users. Given such use case calling guard()
only the server-side is potentially a safety hazard, but maybe that's something we can warn the user about.
Closing but let's continue the conversation and let's see if the guard()
can be improved.
from vike.
In my case, guard() is necessary to display the authentication page if the user is not authenticated (no token or it has expired).
Utilized:
- REST API (server-side not in JavaScript)
- Authentication using access and refresh tokens.
No server-side JavaScript logic for data retrieval, checks, etc. is planned.
In guard(), I plan the following:
- Reading the token from the browser's local storage.
- Checking the token's expiration date (JWT token stores this information).
- Rendering "/auth" if any of the first two steps are not successfully passed.
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.
from vike.
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 guard()
hook be called on the server-side.
from vike.
I apologize for not paying attention to the topic I initiated myself.
To further clarify, the issue is related to a SPA scenario, so ssr
is set to false. In this context, I believe it makes perfect sense to handle the redirection on the client side.
from vike.
Indeed, that makes sense. Re-opening.
from vike.
Related Issues (20)
- Vike Bug during SSR generation HOT 10
- Query Regarding Page Navigation in Vike Software
- crash app in build mode after update vike from 0.4.165 to 0.4.168 HOT 1
- How to set scrollPosition to auto HOT 6
- Bug reported due to HMR overlay HOT 4
- UncaughtException issue HOT 1
- history.state.triggedby and history.state.triggeredby HOT 7
- New hook `onRequestBegin()`
- Styled component's classname did not match the server issue with HMR
- New CLI commands `$ vike routes`, `$vike pages`, and `$ vike config`
- Vike StrictMode
- `urlParsed` removes trailing slash HOT 9
- Offer `href` in `urlParsed` HOT 2
- React native web error: __vite_ssr_import_0__.default is not a function
- Env Leak (Vite, Vike, Vike-Solid, Bun) HOT 9
- Error previewing built Vike app when using Vite Legacy plugin HOT 1
- build error HOT 3
- New setting `crawlWithGit`
- Ubuntu WSL - Connection was reset HOT 9
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 vike.