nextauthjs / nextauthjs/next-auth
isDate() returns true for non dates in edge cases that make use of delimiters '#' or '-' (possibly more).
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Adapter type
@next-auth/supabase-adapter
Environment
System:
OS: Windows 10 10.0.22621
CPU: (16) x64 AMD Ryzen 9 5900HX with Radeon Graphics
Memory: 18.21 GB / 31.42 GB
Binaries:
Node: 19.6.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 9.4.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22621.1555.0), Chromium (112.0.1722.48)
Internet Explorer: 11.0.22621.1
npmPackages:
@next-auth/supabase-adapter: ^0.2.1 => 0.2.1
Reproduction URL
https://github.com/nerkmind1337/modmaster/blob/main/src/lib/auth.ts
Describe the issue
The official Supabase adapter for NextAuth has a bug in the isDate function, which incorrectly formats usernames containing hashtags as dates. This causes unexpected behavior when usernames are processed, resulting in incorrect date representations and subsequent issues in user management.
How to reproduce
Steps to Reproduce
clone repo linked, go to file I linked in the URL, remove this "stupid fix" block
//heres the stupid extra call i reffed in stupidFix.ts
let sf = await stupidFix(user.id)
if (sf) {
session.user.id = sf.id
session.user.name = sf.name
}
Note: im calling my fix stupid (because it is), not anyone else :P
now simply log out what "Session.user" or even "user" returns.
Assuming you have data in your table, you'll get a name returned as a date string. IF, the name contains a '#' EG. nerkmind#1337
Im also pretty sure this will happen with other delimiters. I also tested '-' .
Make sure you seed your supabase DB with the nextauth seed. I just used the default one from the docs.
proposed change
isDate should work like this instead.
function isDate(str: string): boolean {
const date = new Date(str);
return !isNaN(date.getTime()) && date.toString() !== 'Invalid Date';
}
In this version, we use getTime() to obtain the numeric value representing the date from the Date object. We then check if the obtained value is not NaN and the string representation of the date is not 'Invalid Date'.
I have tested this, but may have missed some edge cases. I'll submit a PR with my fix and see what you all think :)
Expected behavior
Expected Behavior
The isDate function should correctly identify whether a given input is a valid date string and avoid formatting usernames containing hashtags as dates.
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 reproduction in src/lib/auth.ts and inspect the Supabase adapter's isDate implementation. Seed the Supabase database with the NextAuth example data, reproduce the session output using names containing '#' or '-', and verify that those names are no longer returned as date strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, nodejs, supabase, typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100