Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSession without token request #3789

Closed
hboylan opened this issue Feb 2, 2022 · 3 comments
Closed

getSession without token request #3789

hboylan opened this issue Feb 2, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@hboylan
Copy link
Contributor

hboylan commented Feb 2, 2022

Description 📓

I originally asked this question in discussions. It appears that there isn't currently support for this feature so I'd like to investigate whether I can contribute a solution for it.

Long story short, I want await getSession(ctx) to resolve an existing session if one is already set in the request cookies. Currently, it fetches a new token every time. This may be nice for some use cases, but I would like to avoid the latency overhead whenever possible.

How to reproduce ☕️

See the related Q&A topic.
#3763

Contributing 🙌🏽

Yes, I am willing to help implement this feature in a PR

@hboylan hboylan added the enhancement New feature or request label Feb 2, 2022
@balazsorban44
Copy link
Member

This is going to be addressed through getServerSession already. This is almost ready, just currently undocumented. See #1535 (comment)

You can actually already do import { getServerSession } from "next-auth/next"

@hboylan
Copy link
Contributor Author

hboylan commented Feb 3, 2022

Thank you @balazsorban44! I also found this method while testing and while it does not use HTTP to request the session, it will make a request for the token every time.

This adds noticeable latency to page transitions, especially when coupled with API requests. Do you think we should support the option to skip the token request when fetching an existing session?

@hboylan
Copy link
Contributor Author

hboylan commented Feb 3, 2022

Oh my gosh. My jwt callback was refreshing the token, which was causing the latency. 🤦🏻

getServerSession works perfectly for my scenario. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants