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

V5 signin() throws error when using redirect: false #9279

Closed
herkulano opened this issue Nov 29, 2023 · 22 comments · Fixed by #9286
Closed

V5 signin() throws error when using redirect: false #9279

herkulano opened this issue Nov 29, 2023 · 22 comments · Fixed by #9286
Labels
bug Something isn't working providers triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@herkulano
Copy link

herkulano commented Nov 29, 2023

Provider type

Email

Environment

System:
OS: macOS 14.1.1
CPU: (8) arm64 Apple M1 Pro
Memory: 872.53 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v18.18.2/bin/npm
bun: 1.0.14 - ~/.bun/bin/bun
Watchman: 2023.11.20.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 119.0.6045.199
Safari: 17.1

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

In "next-auth": "5.0.0-beta.4" the signIn() with redirect: false throws the following error on the client side:

Uncaught (in promise) TypeError: Failed to construct 'URL': Invalid base URL
    at signIn (webpack-internal:///(:3000/en/auth/app-pages-browser)/../../node_modules/next-auth/react.js:172:19)

How to reproduce

Install:

"next-auth": "5.0.0-beta.4"

Run:

const authResponse = await signIn("email", {
      email: data.email,
      redirect: false
})

Expected behavior

Should not throw error

@herkulano herkulano added bug Something isn't working providers triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Nov 29, 2023
@datagutt
Copy link

datagutt commented Nov 29, 2023

This PR seems to have tried to fix an issue with constructing the error URL:
#9056

But baseUrl seems to return the basePath instead of an base url (since we are on the client):

export function apiBaseUrl(__NEXTAUTH: AuthClientConfig) {
if (typeof window === "undefined") {
// Return absolute path when called server side
return `${__NEXTAUTH.baseUrlServer}${__NEXTAUTH.basePathServer}`
}
// Return relative path when called client side
return __NEXTAUTH.basePath
}

@tills13
Copy link
Contributor

tills13 commented Nov 29, 2023

PR ^ contains fix for this issue.

@pulgueta
Copy link

pulgueta commented Dec 9, 2023

I am getting this same issue but with credentials provider instead of email. Already have latest beta update and still not working. Note that I am using signIn from "next-auth/react" instead of exporting it from my auth.config.ts file since it throws an error from webpack.

@Meierschlumpf
Copy link

When the next beta release is planed?

@henriques4nti4go
Copy link

same issue

@eliza921
Copy link

Same issue here with credentials provider...

@aliceclv
Copy link

Same issue 👍

@RoyBkker
Copy link

Having same issue :-(

@cassioseffrin
Copy link

Same issue for me too!

@kitchenbeats
Copy link

Same.

@lucasdale99
Copy link

lucasdale99 commented Dec 29, 2023

Same issue! When will this make it to the next version?

@glenntws
Copy link

glenntws commented Jan 1, 2024

Would also like to get a new beta release ASAP for next-auth. Currently waiting for this one, since patching it out locally is quite tedious....

@pulgueta
Copy link

pulgueta commented Jan 2, 2024

I managed to solve the issue. Simply export the signIn method from the NextAuth class and use it in a server action. Something like this:

image
image

@RicSala
Copy link

RicSala commented Jan 2, 2024

I managed to solve the issue. Simply export the signIn method from the NextAuth class and use it in a server action. Something like this:

image image

That's not solving the issue but changing the environment (client --> server)...

@RicSala
Copy link

RicSala commented Jan 2, 2024

Same issue

@tills13
Copy link
Contributor

tills13 commented Jan 2, 2024

I'll unsubscribe myself from this thread but can we please just thumbs-up the issue or PR instead of commenting "same"

@beaniebag
Copy link

I managed to solve the issue. Simply export the signIn method from the NextAuth class and use it in a server action. Something like this:
image image

That's not solving the issue but changing the environment (client --> server)...

From authjs.dev's docs. It seems handling the formdata server side is the given solution:
https://authjs.dev/reference/nextjs#signin

Hopefully a fix for client side to properly handle errors will come later

@primostasis123
Copy link

i have encounter same issue.. any update on this?

@emimaricic
Copy link

same issue... did you guys manage to find a solution?

@glenntws
Copy link

beta5 includes the patch

@netrolite
Copy link
Contributor

netrolite commented Jan 23, 2024

I fixed this by upgrading to 5.0.0-beta.5

codingjamee referenced this issue in codingjamee/pruru_front Mar 15, 2024
TypeError: Failed to construct 'URL': Invalid base URL
at signIn (react.js:173:19)
at async onSubmit (LoginForm.tsx:48:7)
at async eval (index.esm.mjs:2068:21)
https://github.com/nextauthjs/next-auth/issues/9279\#issuecomment-1906282232
동일한 에러로 해결한 사람의 이슈 댓글 발견하여 에러 해결
@alexdsgmoura
Copy link

Same issue here with credentials provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working providers triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

Successfully merging a pull request may close this issue.