Skip to content

Ensure trigger is set in JWT callback when update() is called #12919

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/next-auth/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,16 @@ export function SessionProvider(props: SessionProviderProps) {
async update(data: any) {
if (loading) return
setLoading(true)
const csrfToken = await getCsrfToken()
// If the body property is not defined, a GET request will be sent instead of a POST.
// As a result, the trigger property in the JWT callback won't be set,
// making it impossible to know if the user data should be re-fetched
// (when the session data updates are handled inside the JWT callback)
const newSession = await fetchData<Session>(
"session",
__NEXTAUTH,
logger,
typeof data === "undefined"
? undefined
: { body: { csrfToken: await getCsrfToken(), data } }
{ body: { csrfToken, data: typeof data === "undefined" ? undefined : data } }
)
setLoading(false)
if (newSession) {
Expand Down