-
Notifications
You must be signed in to change notification settings - Fork 389
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
[SDK-3332] Constrain session lifecycle to withPageAuthrequired
to avoid Next warning
#664
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
withPageAuthrequired
to avoid Next warning
* @category Server | ||
*/ | ||
export type WithPageAuthRequiredOptions<P = any, Q extends ParsedUrlQuery = ParsedUrlQuery> = { | ||
getServerSideProps?: GetServerSideProps<P, Q>; | ||
returnTo?: string; | ||
authRequired?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is an authRequired
option on withAuthRequired
the best way to go? It kind of defeats the entire purpose of withAuthRequired
. Should we go with a different wrapper instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that (eg withPageAuth
or withSessionInitialised
etc) - but decided this would be the easiest to grok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that should determine the design of this feature (documenting it well along with a clear name can make it easy to grok as well). I'll leave it up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give it another thought, I'll see if I can come up with a good name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went for getServerSidePropsWrapper
in e523099 (wait until after your day off to take a look :P)
Description
Next.js >=12 have started to issue a warning (
You should not access 'res' after getServerSideProps resolves.
), and in some cases an error, when you access the response object aftergetServerSideProps
has run.Because this SDK provides a rolling session by default, it writes to the response at the end of every request. It does this at the end of the request using on-headers, which causes the warning because
on-headers
executes aftergetServerSideProps
resolves.We can fix this in
withAuthenticationRequired
by not usingon-headers
and writing to the headers just beforewithAuthenticationRequired
completes, eg.If you want to use
getSession
(andgetAccessToken
) without requiring auth on your route, you'll still need to use thewithAuthenticationRequired
wrapper, but you can do this now with theauthRequired: false
option. egI also fixed an issue in
withAuthenticationRequired
whenprops
is a Promise, egReferences
https://nextjs.org/docs/messages/gssp-no-mutating-res
fixes #524
Testing
Run the basic example app and notice that there is no warning when visiting
/protected
Checklist
main