wobsoriano / fastify-next-auth

Auth.js plugin for Fastify.
MIT License
49 stars 3 forks source link

There is a type mismatch between the parameters passed to the function and the expected type. #4

Closed x751685875 closed 1 year ago

x751685875 commented 1 year ago
No overload matches this call.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<AuthConfig, Server<typeof IncomingMessage, typeof ServerResponse>, FastifyTypeProviderDefault, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifyPluginCallback<AuthConfig, Server<typeof IncomingMessage, typeof ServerResponse>, FastifyTypeProviderDefault, FastifyBaseLogger>' is not assignable to parameter of type 'FastifyPluginAsync<AuthConfig, Server<typeof IncomingMessage, typeof ServerResponse>, FastifyTypeProviderDefault, FastifyBaseLogger>'.ts(2769)
import fp from 'fastify-plugin'
import GoogleProvider from '@auth/core/providers/google'
// const AuthPlugin = require('fastify-next-auth')
import AuthPlugin from 'fastify-next-auth'
import { OAUTH_CONFIGS } from '../configs'

export default fp(async (fastify) => {
  fastify.register(AuthPlugin, {
    secret: process.env.AUTH_SECRET,
    trustHost: process.env.AUTH_TRUST_HOST,
    providers: [
      GoogleProvider({
        clientId: OAUTH_CONFIGS.GOOGLE_CLIENT_ID,
        clientSecret: OAUTH_CONFIGS.GOOGLE_CLIENT_SECRET
      })
    ]
  })
})
wobsoriano commented 1 year ago

Thanks for reporting

DillonWhatley commented 1 year ago

Any progress on this? Hitting it myself.

wobsoriano commented 1 year ago

This is an issue on next-auth side and waiting for it to be fixed so I can release a new version. Meanwhile, here's an ugly fix:

import { type Provider } from '@auth/core/providers'

app
  .register(AuthPlugin, {
    providers: [
      GoogleProvider({
        clientId: process.env.GOOGLE_ID,
        clientSecret: process.env.GOOGLE_SECRET,
      }) as Provider,
    ],
  })
teddybee commented 1 year ago

In my case the AuthPlugin itself has the wrong type. "I was expecting FastifyPluginAsync<AuthConfig, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>, but you passed FastifyPluginCallback<AuthConfig, RawServerDefault, FastifyTypeProviderDefault> "

FastifyBaseLogger is missing in generics.

"fastify": "^4.18.0", "fastify-plugin": "^4.5.0",

wobsoriano commented 1 year ago

@teddybee I don't think that's the issue. Check this basic repro - https://github.com/wobsoriano/auth-provider-type-repro

teddybee commented 1 year ago

I am not 100% sure, but i think your index.d.ts should look like this

declare const fastifyNextAuth: fastify.FastifyPluginAsync<AuthConfig, fastify.RawServerDefault, fastify.FastifyTypeProviderDefault, fastify.FastifyBaseLogger>;

declare module 'fastify' {
    interface FastifyInstance {
        getSession(req: FastifyRequest): Session;
    }
}

export { fastifyNextAuth as default, fastifyNextAuth };

Although I still have error with the trustHost field.

P.S.: it is working now, your type is good as well inside a plugin The trustHost line is faulity in the description. It needs to be set to true instead of an url.

wobsoriano commented 1 year ago

Please update to the latest version and use @auth/core >= 0.8.3.