Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

The redirects uses the default environment URL or need setting it? #2456

Closed
IgorDePaula opened this issue Jul 30, 2021 · 7 comments
Closed
Labels
question Ask how to do something or how something works

Comments

@IgorDePaula
Copy link

Question 💬

I push my app to aws amplify, I register, but on login, on got error the redirect action redirect me to localhost and not to provided url.

How to reproduce ☕️

https://develop.d1cwc8lbezfn59.amplifyapp.com/ -> my app

my auth config

import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
import {Auth} from 'aws-amplify'

export default NextAuth({
    pages: {
        error: "/login", // Changing the error redirect page to our custom login page
    },
    callbacks: {
        async session(session, token) {
            return token
        },
    },
    providers: [
        Providers.Credentials({
            name: "Credentials",
            async authorize(credentials) {
                try {
                    const user = await Auth.signIn(credentials.email, credentials.password)
                    if (user) {
                        const data = {
                           name: user.attributes.name, email: user.attributes.email, image:'asdasdasd',id:user.attributes.sub,
                        }
                        return data
                    }
                } catch (e) {
                    const errorMessage = e.message
                    throw new Error(errorMessage + "&email=" + credentials.email)
                }
            },
        }),
    ],
})

Try you register and after do login.

(I'm using cognito, after register, the cognito will send a code for verification for your email, and you need send this code...after this you can login)

Contributing 🙌🏽

No, I am afraid I cannot help regarding this

@IgorDePaula IgorDePaula added the question Ask how to do something or how something works label Jul 30, 2021
@balazsorban44
Copy link
Member

You probably forgot to set the NEXTAUTH_URL environment variable. It is required in production:

https://next-auth.js.org/configuration/options#nextauth_url

@IgorDePaula
Copy link
Author

No, I put this variable
Captura de Tela 2021-07-30 às 09 02 33

@balazsorban44
Copy link
Member

It looks like it's not being picked up for some reason. Try to log the value server-side. Also, unless you deployed the site on a subpath, the NEXTAUTH_URL should be the canonical URL (remove /api/path)

@IgorDePaula
Copy link
Author

I tried alread, but no success.

@IgorDePaula
Copy link
Author

The repository need upload any .env file?

@IgorDePaula
Copy link
Author

I'm using next 11 and, the next auth config is error page is be login, but redirects to error page, why?

@balazsorban44
Copy link
Member

balazsorban44 commented Jul 30, 2021

Really hard to say. Do you have a reproduction?

This is certainly not a problem in next-auth, as far as I can tell.

.env is not necessary.

Read more about environment variables here https://nextjs.org/docs/basic-features/environment-variables

@nextauthjs nextauthjs locked and limited conversation to collaborators Jul 30, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants