Comments (9)
Oh yeah. I messed that up. I just pushed a fix in case you want to take another look
from realworld.
I just bumped the version of SvelteKit which uses the new method signature for handle
from realworld.
https://kit.svelte.dev/docs#hooks-handle
from realworld.
works for me now with:
export async function handle({ request, render }) {
const cookies = cookie.parse(request.headers.cookie || '')
const jwt =
cookies.jwt && Buffer.from(cookies.jwt, 'base64').toString('utf-8')
const user = jwt ? JSON.parse(jwt) : null
request.locals.user = user
const response = await render(request);
return response;
}
Should /hooks/index.js better not reflect the handle({ request }) method?
Or would handling be possible via the
getSession({ headers })
as in your example and I'm missing something?
Thank you
from realworld.
I just tested and am not seeing any issues
Here are the docs for getSession
: https://kit.svelte.dev/docs#hooks-getsession
from realworld.
Should have mentioned it: Need to access a JWT token from the cookie. So by the docs this would be advised against from within getSession.
Works via handle request, so that was just what I could not wrap my head around coming from the hooks/index.json example. Thanks again!
from realworld.
however I don't see handle()
setup in the realworld
example and it is accessing locals.user however handle()
is not present in hooks definitions `https://github.com/sveltejs/realworld/blob/master/src/hooks/index.js``
from realworld.
Thank you! Link above needs correction, btw.
from realworld.
headers
keeps returning as 'undefined' for me. My app probably deviates a bit from this repo, but nevertheless leaving the following in case it helps someone:
I'm now getting headers by an async function, via the request
object.
export async function handle({ request, resolve }) {
const cookies = cookie.parse(request.headers.cookie || '');
const jwt = cookies.jwt && Buffer.from(cookies.jwt, 'base64').toString('utf-8');
request.locals.user = jwt ? JSON.parse(jwt) : null;
const response = await resolve(request);
return response;
}
from realworld.
Related Issues (20)
- Update SvelteKit realword with breaking change "Removing session #5883" and persistent login HOT 2
- Use SvelteKits's provided fetch method for requests HOT 1
- Cannot read properties of null (reading 'split')
- Profile endpoint throwing error HOT 1
- Pages do not change HOT 6
- Fetch failed HOT 1
- demo site is down (realworld.svelte.dev -> 530) HOT 1
- A working demo with authentication HOT 4
- npm install and npm run dev are not working in latest realworld project HOT 1
- Update this project for svelteKit 1.0.0 HOT 1
- Why this project is using form actions for even logout feature? HOT 4
- cookies are not getting set when running npm run dev -- --host HOT 1
- Static site generation of this project giving error. HOT 1
- btoa and atob deprecated HOT 1
- Build generated from adapter-node is not working for realWorld example HOT 1
- Showing validation errors in login form
- Localisation
- Add use of .env files for dev and prod evvironment HOT 4
- How to add remember me functionality at login page in this project? HOT 1
- Something went wrong HOT 2
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 realworld.