Git Product home page Git Product logo

Comments (9)

benmccann avatar benmccann commented on June 13, 2024 1

Oh yeah. I messed that up. I just pushed a fix in case you want to take another look

from realworld.

benmccann avatar benmccann commented on June 13, 2024 1

I just bumped the version of SvelteKit which uses the new method signature for handle

from realworld.

benmccann avatar benmccann commented on June 13, 2024

https://kit.svelte.dev/docs#hooks-handle

from realworld.

rvrm avatar rvrm commented on June 13, 2024

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.

benmccann avatar benmccann commented on June 13, 2024

I just tested and am not seeing any issues

Here are the docs for getSession: https://kit.svelte.dev/docs#hooks-getsession

from realworld.

yadoga avatar yadoga commented on June 13, 2024

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.

eriknyk avatar eriknyk commented on June 13, 2024

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.

yadoga avatar yadoga commented on June 13, 2024

Thank you! Link above needs correction, btw.

from realworld.

yadoga avatar yadoga commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.