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

Add Support for NEXTAUTH_URL_INTERNAL flag in the .env file #749

Closed
ghost opened this issue Sep 12, 2022 · 6 comments
Closed

Add Support for NEXTAUTH_URL_INTERNAL flag in the .env file #749

ghost opened this issue Sep 12, 2022 · 6 comments

Comments

@ghost
Copy link

ghost commented Sep 12, 2022

Yo so I was looking at the nextauth docs and it looks like there's a second flag that can be passed for the internal url if your hosting on your own machine instead of a cloud server.

When provided it uses a the provided url as the internal server url but when not it defaults to the NEXTAUTH_URL flag. The flag is as shown below:

NEXTAUTH_URL_INTERNAL=http://localhost:3000

The docs page explains it like so:

NEXTAUTH_URL_INTERNAL

If provided, server-side calls will use this instead of NEXTAUTH_URL. Useful in environments when the server doesn't have access to the canonical URL of your site. Defaults to NEXTAUTH_URL.

Here is the page I found it at: https://next-auth.js.org/configuration/options

Basically having this option would be useful for people hosting on their own machines instead of on a cloud server.

With this the NEXTAUTH_URL= can be set to:

NEXTAUTH_URL=http://<public_server_ip>:3000

So the settings in the .env would look like this:

NEXTAUTH_SECRET="somesupersecrettwelvelengthword"
NEXTAUTH_URL="http://<public_server_ip>:3000"
NEXTAUTH_URL_INTERNAL="http://localhost:3000"
NEXT_PUBLIC_INVITE_URL="https://discord.com/api/oauth2/authorize?client_id=1003>"
DISCORD_CLIENT_ID="XXXXXXXXXXXXXXXXXXXXXXXXXXX"
DISCORD_CLIENT_SECRET="XXXXXXXXXXXXXXXXXXXXXXXXXXX"
@ghost ghost closed this as completed Sep 12, 2022
@ghost ghost reopened this Sep 12, 2022
@galnir
Copy link
Owner

galnir commented Sep 13, 2022

I think you can just add another redirect URL in the Discord developer portal and call it a day? You wouldn't run the repo on two machines at the same time, so you can set the URL to whatever you need and avoid this?

Am I right or is it more comfortable for you in the way you recommend?

@ghost
Copy link
Author

ghost commented Sep 22, 2022

I think you can just add another redirect URL in the Discord developer portal and call it a day? You wouldn't run the repo on two machines at the same time, so you can set the URL to whatever you need and avoid this?

Am I right or is it more comfortable for you in the way you recommend?

This doesn't actually use two machines. It actually allows the dashboard to work properly from both the internal IP and public IP of the server.

So if you host in your own machine you don't need to have a separate internet provider to use the dashboard.

Without this you have to choose either private dashboard that can only be accessed by the host or Public that can't be accessed by the host.

With this the dashboard can be used by both the host and public users.

See my PR for a working fix implemented.

@Bacon-Fixation
Copy link
Collaborator

im confused, i run master-bot publicly and don't have any issues with getting to the dashboard via http://localhost:3000 or public ip, or the domain name

Does this hide your public ip from the invite url?

For me, I paid for a web domain ($1 a month) so I could obfuscate the public IP from the Invite URL (IP can still be found by looking up the DNS info tho)

Much Love
-Bacon

@ghost
Copy link
Author

ghost commented Sep 22, 2022

im confused, i run master-bot publicly and don't have any issues with getting to the dashboard via http://localhost:3000 or public ip, or the domain name

Does this hide your public ip from the invite url?

For me, I paid for a web domain ($1 a month) so I could obfuscate the public IP from the Invite URL (IP can still be found by looking up the DNS info tho)

Much Love
-Bacon

The problem is when you try to invite it to a server.

It looks for the specified callback Url which only works if you have access to the IP specified.

So if you set NEXTAUTH_URL to http://localhost:3000, only the host system will be able to actually use the dashboard. And if you set NEXTAUTH_URL to http://public_ip:3000 then it will only be useable to users outside your internet connection.

You can connect with http://localhost:3000 regardless but you can't invite the bot or use the dashboard when hosting from your own machine if you don't have both the internal and public IP set.

Whith this the dashboard is useable to both the localhost and public IP.

Naturally this also requires two callback urls but it fixes the issue with hosting from your own machine rather than from a VPN.

As for the domain name. That renders this method completely unneeded since you can add all required IP addresses to the domain name and set the domain name as the NEXTAUTH_URL.

This is just for those who don't want to pay for a domain to be able to use their own dashboard and still have it publicly useable.

@ghost
Copy link
Author

ghost commented Sep 24, 2022

An easier explanation is if you use http://localhost:3000 as the NEXTAUTH_URL than the redirect when logging in will always be http://localhost:3000/auth/discord no matter what system or ip you try to login from. and obviously that won't work if you're not logging in from the host machine. This fixes that issue basically.

Or at the very least that's what it does for me if I don't have the NEXTAUTH_URL_INTERNAL option to separate the public ip from the private ip.

@galnir
Copy link
Owner

galnir commented Sep 25, 2022

merged #757

@galnir galnir closed this as completed Sep 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants