nextauthjs / nextauthjs/next-auth
`signIn` with `RedirectableProviderType` type: `response` is possibly `undefined`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
System:
OS: Linux 5.17 EndeavourOS
CPU: (12) x64 AMD Ryzen 5 4600H with Radeon Graphics
Memory: 5.85 GB / 15.07 GB
Container: Yes
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.14.2/bin/yarn
npm: 8.7.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
npmPackages:
next: ^12.1.5 => 12.1.5
next-auth: ^4.3.4 => 4.3.4
react: ^18.1.0 => 18.1.0
Reproduction URL
https://codesandbox.io/s/objective-mendel-ixpsco?file=/src/App.tsx
Describe the issue
According to documentation when you supply email or credentials provider to signIn function it returns promise of type SignInResponse but in fact return type of the signIn function is Promise<SignInResponse | undefined>.
This typing results in typescript error Object is possibly 'undefined' if you don't check if response exists beforehand.
How to reproduce
- Specify
signIntype to beRedirectableProviderType - Chain
thento function call - Check for
response.error - See typescript error
Expected behavior
When specifying signIn type to be one of RedirectableProviderType the return type should be Promise<SignInResponse> and not Promise<SignInResponse | undefined>
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 linked CodeSandbox reproduction and the signIn client documentation, then trace the signIn type for RedirectableProviderType. Verify that the response.error access no longer produces an undefined warning and that the return type is Promise as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, react, typescript
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100