Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I don't know what went wrong in my deployment. If I do deploy in Vercel the app works fine. But on AWS it is redirecting me to localhost:3000.

I went through similar discussions and applied some suggestions I saw there. Still it is not working as expected.

This is my build file.

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
        - echo "NEXTAUTH_URL=$NEXTAUTH_URL" >> .env

  artifacts:
    baseDirectory: .next
    files:
      - "**/*"
  cache:
    paths:
      - node_modules/**/*

Also have added my environment variables in Amplify console. The variable name is NEXTAUTH_URL

You must be logged in to vote

Replies: 2 comments · 5 replies

Comment options

Hello, I know it's been a while but I have the same problem right now, did you manage to fix it?

You must be logged in to vote
5 replies
@mattmanik
Comment options

Hello, It's fixed after adding NEXT_PUBLIC in my prefix. In AWS, Please make sure you add this env in your yaml file settings and environment variables. Good luck !

@aphavichitr
Comment options

@emimaricic @emimaricic i'm encountering the same issue, did you guys ever find a solution?

@mattmanik
Comment options

@aphavichitr Make sure you add NEXT_PUBLIC in prefix of your env variables

@aphavichitr
Comment options

Adding the NEXT_PUBLIC prefix didn't work for me, what did work is putting the echo "NEXTAUTH_URL=$NEXTAUTH_URL" >> .env in the build file, but you need to put it before the npm run build or at least that's how it worked for me. I followed this thread

@dertin
Comment options

build:
  commands:
    - npm install
    - env | grep -e NEXTAUTH_URL >> .env.production
    - npm run build
Comment options

I ran into the same redirect issue, but in my case I was using WorkOS AuthKit + Next.js (App Router) deployed on AWS Amplify, not NextAuth. Posting this here since the root cause and fix are similar and might help others.

🧩 Problem
After a successful login, my app kept redirecting to https://localhost:3000/dashboard —even in production.
WorkOS was correctly configured with WORKOS_REDIRECT_URI=https:///callback,
but after the callback, the app itself issued a redirect to localhost.

⚙️ Root cause
@workos-inc/authkit-nextjs uses handleAuth() to manage the callback flow.
If you don’t provide a baseURL, it defaults to https://localhost:3000, which causes production redirects to break.

✅ Fix
Add this environment variable in Amplify (or your hosting platform):
NEXT_PUBLIC_URL=https://<<YOUR DOMAIN>>

Then update your /app/callback/route.ts:
import { handleAuth } from '@workos-inc/authkit-nextjs'; const baseURL = process.env.NEXT_PUBLIC_URL || 'http://localhost:3000'; export const GET = handleAuth({ baseURL }); export const POST = handleAuth({ baseURL, returnPathname: '/' });

Now WorkOS redirects correctly to your deployed domain.

✅ Summary:
If your Next.js app (using WorkOS, NextAuth, etc.) redirects to localhost after login,
set your baseURL explicitly — most auth kits default to localhost in the absence of one.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Help
Labels
None yet
5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.