Skip to content
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

state param is not included in the Typescript interface for AuthenticateOptions #595

Closed
2 tasks done
louisnk opened this issue Jun 28, 2022 · 1 comment
Closed
2 tasks done

Comments

@louisnk
Copy link
Contributor

louisnk commented Jun 28, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.x

Plugin version

No response

Node.js version

18.x

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Ubuntu 22.04

Description

This is a Typescript bug.

When using the Passport Google Oauth2 package to implement a Google auth strategy, we are unable to pass the state property though the passport.authenticate options object.

This works code-wise, but does not compile because the interface definition for AuthenticateOptions does not include state.

Working non-TS example here

This is basically an extension of #376 that only appears when devs have the misfortune of using typescript.

Steps to Reproduce

Example code:

const preValidation = async (
    request: FastifyRequest<{
      Querystring: {
        state?: string
      }
    }>,
    reply: FastifyReply,
  ): Promise<void> => {
   const state: string = request.query?.state || ""

  // return passport.authenticate("google", { state, assignProperty: 'state' })(request, reply)
  return passport.authenticate("google", { state, assignProperty: 'state' }, (() => null))(request, reply)
}
...
fastify.get("/auth/google", { preValidation }, async () => "never returns anywhere")

When swapping the commented out lines we get varying errors that state is not defined on the interface for either the SingleStrategyCallback or AuthenticateOptions.

Example: Object literal may only specify known properties, and 'state' does not exist in type 'AuthenticateOptions'.

Expected Behavior

A Typescript developer can pass a state property through the AuthenticateOptions object without error.

airhorns added a commit that referenced this issue Jun 28, 2022
Fixes Issue #595 - Add state prop to AuthenticateOptions interface
@louisnk
Copy link
Contributor Author

louisnk commented Jun 28, 2022

Fixed with #596

@louisnk louisnk closed this as completed Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant