lucia-auth / examples

A collection of example projects built with Lucia
MIT License
171 stars 41 forks source link

optimize `getPageSession` to only send one request on dashboard #3

Closed deadcoder0904 closed 3 months ago

deadcoder0904 commented 9 months ago

i was getting lots of requests for a session that won't change on my dashboard when i switched between 3 tabs.

ideally, it should only request session 1 time but it requested 3 times.

so i asked chatgpt for optimization & it found one:

export const getPageSession = cache(async () => {
    const authRequest = auth.handleRequest("GET", context)
    const session = await authRequest.validate()

    return session
})

image

i checked it & it does send only 1 request.

using next.js example btw :)

pilcrowOnPaper commented 3 months ago

Gonna close these since all examples have been rebuilt for v3