nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.17k stars 3.35k forks source link

signIn() not working #11670

Closed dhruvkaushik305 closed 3 weeks ago

dhruvkaushik305 commented 3 weeks ago

Environment

System:
    OS: Linux 6.8 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 2.52 GB / 7.42 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.15.1/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
    pnpm: 9.6.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 128.0.6613.84
  npmPackages:
    next: 15.0.0-rc.0 => 15.0.0-rc.0 
    next-auth: 5.0.0-beta.20 => 5.0.0-beta.20 
    react: 19.0.0-rc-f994737d14-20240522 => 19.0.0-rc-f994737d14-20240522 

Reproduction URL

https://github.com/dhruvkaushik305/Dkode/blob/main/apps/web/app/_components/Navbar.tsx

Describe the issue

Following the docs, the initialization of the auth.ts itself feels weird as i am seeing typescript errors The inferred type of 'signIn' cannot be named without a reference to '.pnpm/@auth+core@0.34.2/node_modules/@auth/core/providers'. This is likely not portable. A type annotation is necessary.ts(2742) Ignoring that i created the signIn button and when using it server side, the router pushes a /? and then redirects to / without even showing the signinPage. I tried experimenting by making it client side, but nextJs is giving an error then that Error: headers was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context

How to reproduce

Install the dependencies and then hit the dev server, try clicking the signIn button

Expected behavior

It should render the signIn page

balazsorban44 commented 3 weeks ago

The signin method from auth.ts is meant for server actions. For client components keep using the signIn method imported from next-auth/react

dhruvkaushik305 commented 3 weeks ago

Alright, but as i mentioned it isn't working on the server side either.

balazsorban44 commented 3 weeks ago

Couldn't see that in the reproduction.

Maybe check out https://github.com/nextauthjs/next-auth-example

which has a deployed/working example.