-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
callbackUrl seems to be ignored #1542
Comments
There's a solution while this bug isn't fixed. Then on your page:
add this to
thanks for pointing out to |
@bduff9 could you please link to a reproduction? |
I have the same issue. @rmgpinto Thanks for the workaround. I can see that the "next-auth.callback-url" is correctly set, but it seems to ignore it. Running locally (by building / running and with dev server): http://localhost:3000/login_route -> (LOGIN) -> http://localhost:3000/wanted_route Deployed: https://<my_website>.com/login_route -> (Login) -> https://<my_website>.com ??? Any suggestions? EDIT: I'm using docker to build/deploy and the suggested Dockerfile provided by Next.js docs. I tried setting domain with combinations of : httpOnly: false, secure:false, httpOnly: true, secure: true Also tried:
Now both Still redirects to |
Here're some of the efforts I've tried to get callbacks to work but also subdomains too. Specifically if you want to pass provider.callbackUrl = provider.callbackUrl + `?callbackUrl=` + encodeURIComponent(req.options.callbackUrl) Check previous commits in that branch to get a better picture. I know maintainers are focusing on the 4.x branch and options are not exposed there in the same way, but could be useful if you guys decide to revive the subdomains + callbackUrls persisted. |
I'm running in the same issue while trying to use Next Auth as a centralized/common auth infrastructure for cli login. I've created a minimal repro example: https://github.com/geovanisouza92/next-auth-standalone-auth |
I just stumbled upon this issue today. We have an application that serves multiple domains, meaning that the |
I managed to get one step further, by overwriting
Now the The issue now is that when I get back, next-auth attempts to fetch id token, and it fails by sending the wrong
As I am uncertain if my issue is completely related to this issue, I have created another issue #4668. |
I have found a workaround fix (tested locally and production) for this issue by doing the following: in pages: {
signIn: '/login',
}, in callbacks: {
async redirect({ url, baseUrl }) {
// Allows relative callback URLs
if (url.startsWith("/")) return `${baseUrl}${url}`
// Allows callback URLs on the same origin
else if (new URL(url).origin === baseUrl) return url
return baseUrl
},
} in custom login page (e.g import { signIn } from 'next-auth/react'
import { useRouter } from 'next/router'
const router = useRouter()
signIn('credentials', {
redirect: false,
callbackUrl: `${
router.query.callbackUrl
? router.query.callbackUrl
: window.location.origin
}`,
}) in any page (e.g: export async function getServerSideProps(context) {
const { req, resolvedUrl } = context
const session = await getSession({ req })
const destination = `${process.env.NEXTAUTH_URL}${resolvedUrl}`
const callbackUrl = `/login?callbackUrl=${encodeURIComponent(destination)}`
if (!session) {
return {
redirect: {
destination: callbackUrl,
permenant: false,
},
}
}
if (session) {
return {
props: {
session,
},
}
} |
I had a similiar issue and fixed it by specifiying the NEXTAUTH_URL with the proper base domain like https://example.org. This properly reformatted the callback url to my expected host. |
@ShadiBlitz This worked very well. Thanks so much for sharing. I'm assuming that when we implement a custom sign in page, we opt-out of the default auto callBackUrl functionality? If this is true, I'd love to see this added as an info blurb in the documentation. |
This helped me understand why when I was using a custom basePath my project didn't get the right callbackUrl while using I thought my NEXTAUTH_URL had to be
When it had to be
Then the callbackUrl started to reflect the proper value 😉 To see your export default NextAuth({
debug: true,
providers: [
....
}) |
I for the life of me can't figure out how to use Next Auth with ngrok. My URLs keep changing on every app build, and the redirect Url is always incorrect. Has anyone got Next Auth and ngrok working? |
same issues . Google provider can redirect collectly, but Apple provider not. i don't know why same logic cause two different result. |
Please check if setting the env I was only searching for callbackUrl because my next url was not correct. Fixing it, fixed my issue. Leaving no other changes - especially to the callbackUrl - necessary at all. |
thank you for your help. but i don't think my setting is wrong. when use debug true, only problem is when use apple provider get the wrong cookies callback Url. i don't know where it was come from. maybe i can update it before goto sns auth page.
|
finally, i change the cookies's sameSite to none it work. |
I cannot reproduce this issue in v4, so I'll close it. Feel free to reopen a new issue if you still have the problem 🙇♂️ |
The magic for me was putting the right callback url in the signIn method: <button
onClick={()=> signIn('google', {
callbackUrl: `${new URLSearchParams(window.location.search).get('callbackUrl')}`
})}
>
Sign in with Google
</button> |
I'm using a custom Oauth provider setup, and have the same issue. I feel like the server-side |
I added to the .env.local file in the root, NEXTAUTH_URL=<your_domain>api/auth |
Describe the bug
Using callbackUrl with email, google, and twitter providers. I would expect the application to redirect to this URL after successful sign-in. Instead, it always redirects to the root.
Steps to reproduce
..where callbackUrl is currently hardcoded to
http://localhost:3000/picks/set
. I have confirmed this value, however, there is a cookie I see with the namenext-auth.callback-url
that is always set tohttp%3A%2F%2Flocalhost%3A3000
.Expected behavior
I would expect the application to be redirected to http://localhost:3000/picks/set after successful authentication.
Screenshots or error logs
N/A
Additional context
I am using the latest NextAuth (3.13.0) and NextJS (10.0.9). Node version is 14.15.4.
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
The text was updated successfully, but these errors were encountered: