nextauthjs / nextauthjs/next-auth
merge function does not correctly merge objects
Open
Nobody has claimed this yet.
bug
triage
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
const target = {
sessionToken: {
name: "authjs.session-token",
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: false,
},
}
}
const source = {
sessionToken: {
options: {
expires: new Date("2024-01-01T00:00:00Z"),
},
}
}
// Call
merge(target, source)
const expected = {
sessionToken: {
name: "authjs.session-token",
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: false,
expires: source.sessionToken.options.expires,
},
}
}
// Actual result
Object {
"sessionToken": Object {
"name": "authjs.session-token",
"options": Object {
- "expires": 2024-01-01T00:00:00.000Z,
+ "expires": Object {},
"httpOnly": true,
"path": "/",
"sameSite": "lax",
"secure": false,
},
},
}
See PR: https://github.com/nextauthjs/next-auth/pull/13030
Reproduction URL
https://github.com/magom001/operaclass.net/tree/nextauth
Describe the issue
Merge function does not correctly merge objects. E.g., it treats Date as a regular Object.
How to reproduce
Add the following test to merge.test.ts:
it("should handle merging Date object", () => {
const target = {
sessionToken: {
name: "authjs.session-token",
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: false,
},
},
}
const source = {
sessionToken: {
options: {
expires: new Date("2024-01-01T00:00:00Z"),
},
},
}
const expected = {
sessionToken: {
name: "authjs.session-token",
options: {
httpOnly: true,
sameSite: "lax",
path: "/",
secure: false,
expires: source.sessionToken.options.expires,
},
},
}
expect(merge(target, source)).toEqual(expected)
})
Expected behavior
merge correctly merges objects
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the merge implementation and the existing merge.test.ts file, then add the provided Date-object reproduction. Run the merge tests and confirm that the nested expires value remains a Date while the other sessionToken.options fields are preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100