docs: Protected Routes: Best Practice?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the problem
It's a common scenario to have protected routes. It would be great if the docs would outline the best practice for doing this in sveltekit.
Describe the proposed solution
I would think that the hooks.server.js is the best place to check the current path, and act if a user is on a route and (for example) not authenticated.
Alternatives considered
Adding a server.js file per route, but this won't handle any subroutes.
Ex:
/api/server.js <- redirect request
/api/secrets <- still accessible
Importance
would make my life easier
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the protected-route guidance around hooks.server.js and the alternative per-route server.js approach described in the issue. Document the recommended SvelteKit pattern for checking authentication and covering subroutes, with an example that makes the expected redirect behavior clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- authentication, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100