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

4.18.4 no longer respects signIn(..., {redirect: false}) #6001

Closed
EvHaus opened this issue Dec 9, 2022 · 8 comments · Fixed by #6004
Closed

4.18.4 no longer respects signIn(..., {redirect: false}) #6001

EvHaus opened this issue Dec 9, 2022 · 8 comments · Fixed by #6004
Labels
bug Something isn't working core Refers to `@auth/core`

Comments

@EvHaus
Copy link

EvHaus commented Dec 9, 2022

Environment

System:
OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 24.48 GB / 31.32 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 17.8.0 - ~/.nvm/versions/node/v17.8.0/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.5.5 - ~/.nvm/versions/node/v17.8.0/bin/npm
npmPackages:
next: 13.0.6 => 13.0.6
next-auth: 4.18.0 => 4.18.0
react: 18.2.0 => 18.2.0

Reproduction URL

https://stackblitz.com/edit/github-61ga3k-pvybxx?file=pages%2Findex.tsx,pages%2Fapi%2Fauth%2F[...nextauth].ts

Describe the issue

After upgrading from 4.18.0 to 4.18.4 I noticed that signIn(..., {redirect: false}) is no longer respecting the redirect: false option.

In my app I have a CredentialsProvider and I issue a signIn request like this:

const result = await signIn('myapp-login', {
    {username, password},
    redirect: false,
});

In 4.18.0, after a successful login, it this would return:

{
    error: null,
    ok: true,
    status: 200,
    url: "http://localhost:3000/login"
}

But in 4.18.4 it returns:

{
    error: null,
    ok: false,
    status: 302,
    url: "http://localhost:3000/login"
}

How to reproduce

Create an example app with [email protected] and update the signIn() call in the header to use the redirect: false option. Proceed to login and check the response of the signIn() request.

Expected behavior

The signIn() call should resolve with an ok: true object upon successful login.

@EvHaus EvHaus added the triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. label Dec 9, 2022
@balazsorban44
Copy link
Member

Identified the issue, here is an experimental release to test out: #6004 (comment)

@balazsorban44 balazsorban44 added bug Something isn't working core Refers to `@auth/core` and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Dec 9, 2022
@violabg
Copy link

violabg commented Dec 9, 2022

I have the same issue, it started with the release of v 4.18.1.
I have tested with pnpm add [email protected], and I confirm that is working.
Thanks

@balazsorban44
Copy link
Member

This should be fixed in 4.18.5, please give it a try!

@balazsorban44
Copy link
Member

Please open a new issue with a minimal reproduction.

@TerrySlack
Copy link

I'm still getting this in 4.18.7. Reverted to 4.18.0 and the issue is still there.
However, when using 4.18.5, the error is not there.

@nmicun
Copy link

nmicun commented Jan 23, 2023

I have the same problem with @auth/core 0.2.5 in SvelteKit, redirect: false is not working, response is undefined.
Solved by removing !error from if statement:

 if (redirect || !isSupportingReturn || **!error**) 
{
    // TODO: Do not redirect for Credentials and Email providers by default in next major
    window.location.href = data.url ?? callbackUrl
    // If url contains a hash, the browser does not reload the page. We reload manually
    if (data.url.includes("#")) window.location.reload()
    return

  }

@binaryme
Copy link
Contributor

@nmicun I discovered the same behavior in sveltekit, but instead of removing error I opted for converting error to a boolean:
if (redirect || !isSupportingReturn || Boolean(error)) { // TODO: Do not redirect for Credentials and Email providers by default in next major window.location.href = data.url ?? callbackUrl; // If url contains a hash, the browser does not reload the page. We reload manually if (data.url.includes("#")) window.location.reload(); return; }

I console logged the evaluated variables and discovered that if there is no error, error returns null
🚀 ~ file: client.js:10 ~ signIn ~ redirect: false client.js:15 🚀 ~ file: client.js:15 ~ signIn ~ isSupportingReturn: true client.js:38 🚀 ~ file: client.js:37 ~ signIn ~ error: null

that's why removing error in your case temporarily fixed the issue.

@WolfVector
Copy link

I'm also using sveltekit, In my case I fixed it by doing

if ((redirect || !isSupportingReturn) && !error) {
  // TODO: Do not redirect for Credentials and Email providers by default in next major
  window.location.href = data.url ?? callbackUrl;
  // If url contains a hash, the browser does not reload the page. We reload manually
  if (data.url.includes("#")) window.location.reload();
  return;
}

res.error = error
return res

Just like @binaryme said, error is null when the signIn is successfull and it is a string when there is an error. So in this way, the returned object will have the error property and you could check what value it has.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core Refers to `@auth/core`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants