nextauthjs / nextauthjs/next-auth

`signIn` with `RedirectableProviderType` type: `response` is possibly `undefined`

Open
#4,513 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage TypeScript
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
  1. Specify signIn type to be RedirectableProviderType
  2. Chain then to function call
  3. Check for response.error
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.