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

bug: Unable to sign in with Discord #2039

Open
shrekuu opened this issue Dec 4, 2024 · 1 comment
Open

bug: Unable to sign in with Discord #2039

shrekuu opened this issue Dec 4, 2024 · 1 comment

Comments

@shrekuu
Copy link

shrekuu commented Dec 4, 2024

Provide environment information

npx envinfo --system --binaries

System:
OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (2) x64 AMD EPYC 7R32
Memory: 2.24 GB / 3.78 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
pnpm: 9.14.4 - ~/.nvm/versions/node/v20.14.0/bin/pnpm

ct3aMetadata.initVersion

7.38.1

Describe the bug

I

  • followed the guide. Copied AUTH_DISCORD_ID AUTH_DISCORD_SECRET into .env file.
  • Tried both sqlite and mysql db.
  • Added NEXTAUTH_URL=https://try-t3-app.linwise.com/ in .env too.

It works when I run "pnpm dev", both on my local machine and on the debian server.

It does not work after I run "pnpm build" and use pm2 to start it like this:

next.js config, no standalone output way:
PORT=3006 pm2 start npm --name try-t3-app -- start

next.js config, standalone output way:
PORT=3006 pm2 start .next/standalone/server.js --name try-t3-app

I can open the page: https://try-t3-app.linwise.com/
Surprisingly, you see on the page it says "Logged in as", and "sign out".
I cleared all the cookies, and tried browser incognito mode. It still does not work.

When I go to https://try-t3-app.linwise.com/api/auth/signin, it says Server error.

This is the redirect url I have on discord oauth2 settings page:
https://try-t3-app.linwise.com/api/auth/callback/discord

Reproduction repo

https://github.com/shrekuu/try-t3-app

To reproduce

Just build the app and serve it locally. Update the AUTH_DISCORD_ID, AUTH_DISCORD_SECRET, DATABASE_URL in your local .env file.

You may need to add NEXTAUTH_URL="http://localhost:3000" too.

Make sure to use MySQL, if not, revert these changes and you are good to go.
shrekuu/try-t3-app@90e04df

Additional information

@shrekuu
Copy link
Author

shrekuu commented Dec 5, 2024

Figured it out.

Had to add AUTH_TRUST_HOST="try-t3-app.linwise.com" to .env file.

https://authjs.dev/getting-started/migrating-to-v5#environment-variables

So these two lines are necessary for discord to work properly.

NEXTAUTH_URL="https://try-t3-app.linwise.com"
AUTH_TRUST_HOST="try-t3-app.linwise.com"

Maybe we should add these two lines in .env when users create t3 app?

NEXTAUTH_URL="http://localhost"
AUTH_TRUST_HOST="localhost"

@shrekuu shrekuu changed the title bug: Unable to use discord login with production build bug: Unable to sign in with Discord Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant