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

Typescript errors when using customer provider #1752

Closed
5 tasks
bhaskarmurthy opened this issue Apr 17, 2021 · 1 comment
Closed
5 tasks

Typescript errors when using customer provider #1752

bhaskarmurthy opened this issue Apr 17, 2021 · 1 comment
Labels
bug Something isn't working TypeScript Issues relating to TypeScript

Comments

@bhaskarmurthy
Copy link

bhaskarmurthy commented Apr 17, 2021

Describe the bug
I'm getting a type error when passing a custom Provider to the NextAuth method.

Error 1
When passing an id to the provider config, there's an error about Type 'string' is not assignable to type 'undefined'.

Error 2
However, if I don't set the id property, I get a different error about Object literal may only specify known properties, and 'protection' does not exist in type 'Provider<undefined, "oauth">'

Error 3
I'm also getting another type error if for domain if I set the Provider type using the template:
const customProvider: Provider<'custom'> = {...}

Error:
Property 'domain' is missing in type 'Provider<"custom", "oauth">' but required in type '{ domain: string; }'

import NextAuth from "next-auth";
import { Provider } from "next-auth/providers";

const customProvider: Provider = {
  // required
  id: "custom",
  name: "Custom Provider",
  type: "oauth",
  version: "2.0",
  accessTokenUrl: process.env.OAUTH_TOKEN_URL,
  authorizationUrl: `${process.env.OAUTH_AUTHORIZE_URL}?response_type=code`,
  clientId: process.env.OAUTH_CLIENT_ID,
  // optional
  params: { grant_type: "authorization_code" },
  protection: ["pkce", "state"],
};

export default NextAuth({
  providers: [customProvider],
  // debug: true,
});

Steps to reproduce
Steps to reproduce the behavior.

Include a link to public repository which can be used to reproduce the behaviour.

Expected behavior
If I set the id to be a string constant using the Provider<'custom'> type, I should be able to set the protection optional value (as per the docs)

Screenshots or error logs
If applicable add screenshots or error logs to help explain the problem.

Additional context
Add any other context about the problem here.

Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.

  • Found the documentation helpful
  • Found documentation but was incomplete
  • Could not find relevant documentation
  • Found the example project helpful
  • Did not find the example project helpful
@bhaskarmurthy bhaskarmurthy added the bug Something isn't working label Apr 17, 2021
@balazsorban44
Copy link
Member

a big rewrite and built-in types are coming soon, watch out for

#1690

it will first be merged to beta, then soon after to main.

hopefully that should address all your problems.

if not, feel free to repoen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working TypeScript Issues relating to TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants