next-auth: `providers` doesn't accept type `OAuthConfig`
Environment
System: OS: Windows 10 10.0.22000 CPU: (4) x64 11th Gen Intel® Core™ i3-1115G4 @ 3.00GHz Memory: 2.03 GB / 7.73 GB Binaries: Node: 16.16.0 - ~\scoop\apps\nodejs-lts\current\node.EXE npm: 8.11.0 - ~\scoop\apps\nodejs-lts\current\npm.CMD Browsers: Edge: Spartan (44.22000.120.0), Chromium (108.0.1462.54) Internet Explorer: 11.0.22000.120
Reproduction URL
https://github.com/nextauthjs/sveltekit-auth-example
Describe the issue
the providers
option in SvelteKitAuth
accepts type Provider<Profile>[]
but the Github
Provider is of type OAuthConfig<GithubProfile>
https://github.com/nextauthjs/next-auth/issues/6170#issuecomment-1364538419
Error: Type 'OAuthConfig<GithubProfile>' is not assignable to type 'Provider<Profile>'.
Type 'OIDCConfig<GithubProfile>' is not assignable to type 'Provider<Profile>'.
Type 'OIDCConfig<GithubProfile>' is not assignable to type 'OIDCConfig<Profile> & { options: Record<string, unknown>; }'.
Type 'OIDCConfig<GithubProfile>' is not assignable to type 'OIDCConfig<Profile>'.
Types of property 'profile' are incompatible.
Type 'ProfileCallback<GithubProfile> | undefined' is not assignable to type 'ProfileCallback<Profile> | undefined'.
Type 'ProfileCallback<GithubProfile>' is not assignable to type 'ProfileCallback<Profile>'.
Types of parameters 'profile' and 'profile' are incompatible.
Type 'Profile' is missing the following properties from type 'GithubProfile': login, id, node_id, avatar_url, and 26 more.
How to reproduce
Clone the repo, install deps, navigate to the hooks.server.ts
file or run pnpm check
Expected behavior
there shouldnt be any type error
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 34
- Comments: 34 (5 by maintainers)
Commits related to this issue
- Switching off TS error per https://github.com/nextauthjs/next-auth/issues/6174 — committed to arackaf/booklist by arackaf 2 years ago
This is kind of embarrassing, out of the box default example throws this type errors, bypassing the type checker is not a solution
Let’s get the issue fixed, every single user trying auth.js with typescript hits this issue and makes no sense.
Same issue here. Working around:
Including “just ignore the red underlines” should never be considered.
TypeScript complains for a reason, so this should be fixed, bypassing the linting and disabling ts checks is just a temporary solution and shouldn’t be considered a regular practice and should not be mentioned in the docs. Ever.
I literally checked 2 hours ago if this has been resolved, go away stale bot.
I did some digging and it looks like it’s the inconsistency between interface
Profile
between packagesas you can see one of them accepts
string | undefined
while the other only doesstring | undefined | null
. I tried changing the latter tostring | undefined
however I’m not familiar with the codebase and runninglint
on the project doesn’t seem to catch the error either way, also theapps/dev/sveltekit/hooks
file doesn’t seem to grab types from the auth/sveltekit package properly for me.Just commenting to avoid stale bot. Is also happening to me, using sveltekit and drizzle adapter
Just hit this. Commenting to avoid stale bot.
Hey @enBonnet, I still had to typecast it using
Not SvelteKit specific. When a provider is imported, it should extend the
Profile
interface, so it’s correctly typed in places like thejwt
callback.The tricky part is that it should be dependent on the value of
Account#providerAccountId
.Eg.:
We can tackle half the problem by module augmentation, i.e.:
Adding this to https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/github.ts
But the last I tried, I could not augment the same interface with more than one Profile at the same time.
If TypeScript gurus read this, help would be appreciated!
November stale bot comment, still revisiting this often a month
When I tried this, I realised that the
@auth/sveltekit
is using@auth/core@0.3.0
but the latestauth/core
is0.4.0
, pinning the version of@auth/core
fixed it for me.Definitely agree it should be fixed, but at least a note in the docs in the meantime couldn’t hurt.
This sounds like perhaps a backwards way to do it. You’re essentially tricking the TS compiler into thinking GithubProfile matches the interface of Profile, which can make the error go away, but doesn’t solve the root problem.
Semantically, I would expect the opposite: GithubProfile (more specific) should be an extension of Profile (more general). I’m not that familiar with the internal types of AuthJS yet, but I think this is written incorrectly (or at least oddly):
@auth/core/src/providers/github.ts
Here we’re telling TS that the generic type used within the function (Profile) should extend from GithubProfile, but shouldn’t the actual GithubProfile type extend from the actual Profile type instead?:
@auth/core/src/providers/index.ts
Which would make this closer to the solution?
@auth/core/src/providers/github.ts
Then, we don’t need to provide the generic with an extension. We just let TS do its job. Just seems like there’s a lot of odd TS stuff under the hood here. It looks like the type mismatch is still further down in inference, within the OAuthUserConfig type.
It has been a long time with this issue open, almost a year, I see that in the official examples we are using the
satisfies NextAuthConfig
approach there is the example: https://github.com/nextauthjs/next-auth/blob/465e882176de5c9e1bc5a482c429ba8d54c55e22/apps/examples/nextjs/auth.ts#L143C27-L144C1Maybe we should update the docs for TS to add this instead of going through every provider to fix it?
Good use case for satisfies in the meantime:
I don’t think so, this is just a workaround, we should fix it instead.