CONNECTION REFUSED for Next Auth app deployed in AWS Amplify facebook logic

74 views Asked by At

I have a NextJS 13 webapp deployed in AWS Amplify with NextAuth 4 oauth logic configured for facebook.

Logic works find locally and I can login using facebook. In the Amplify build I am passing environmental variables as follows

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - echo "NEXTAUTH_URL=$NEXTAUTH_URL" >> .env
        - echo "NEXTAUTH_SECRET=$NEXTAUTH_SECRET" >> .env
        - echo "FACEBOOK_ID=$FACEBOOK_ID" >> .env
        - echo "FACEBOOK_SECRET=$FACEBOOK_SECRET" >> .env
        - printenv
        - npm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

I don't think there is a issue with environmental variables not set because when redirect to the facebook login I can see recirect_url query param set to the app host url not the local. When logged in I get redirected to following url

https://my-host/api/auth/error?error=connect%20ECONNREFUSED%20127.0.0.1%3A80#=

In the facebook app I have configured Valid OAuth Redirect URIs to https://my-host/api/auth/callback/facebook. There is a option to test the redirect url in the facebook app at the bottom.

enter image description here

When I enter the actual redirect url which has additional query params other than the base url which has been configured as the valid redirect url, app says it is invalid. Only when additional query params removed it accepts the url as valid. I'm not 100% if this is the issue.

0

There are 0 answers