triggerdotdev / trigger.dev

Trigger.dev is the open source background jobs platform.
https://trigger.dev/changelog
Apache License 2.0
9.39k stars 589 forks source link

Localhost magic link redirect on Safari (MacOS) #1384

Open shaaridev opened 1 month ago

shaaridev commented 1 month ago

Provide environment information

System: OS: macOS 14.4.1 CPU: (8) arm64 Apple M2 Memory: 77.13 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.2.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 10.7.0 - /opt/homebrew/bin/npm

Describe the bug

In safari Browser on mac after you click on the magic link from the email the browser redirect you to the login page ] http://localhost:3040/login?redirectTo=%2F which show you the login page again. This works without issues in chrome. I get redirected to http://localhost:3040/confirm-basic-details

Reproduction repo

https://github.com/triggerdotdev/docker

To reproduce

git clone https://github.com/triggerdotdev/docker cd docker cp .env.example .env follow the self hosting tutorial in the doc to set .env .. ./start.sh go to http://localhost:3040/ in Safari (MacOs) create account and check your email. click on the magic link

Additional information

No response

smoothdvd commented 2 weeks ago

same here, Safari 18.1 (20619.2.8.11.10) / macOS 15.1 / trigger.dev docker 3.1.1

nicktrn commented 2 weeks ago

Are you both testing this on localhost? Webapp and worker on the same machine or split setup? Likely an env var issue as it worked fine when I just tried it with:

git clone https://github.com/triggerdotdev/docker trigger-docker
cd trigger-docker
./start.sh
# then login at http://localhost:3040/

I'd start fresh an see after which step it fails, my guess is it's one of these env vars:

# Only uncomment these once you've set up a domain and are trying to access the webapp through it
# On localhost, these should be commented out as below
# TRIGGER_PROTOCOL=https
# TRIGGER_DOMAIN=<your_subdomain>.ngrok-free.app

For a completely fresh start, you can nuke your DB, reset your .env and pull in any changes like so:

./stop.sh -v
rm .env
git pull
./start.sh
smoothdvd commented 2 weeks ago

This doesn’t explain why it works on Chrome but not on Safari.

nicktrn commented 2 weeks ago

Ah right, I didn't see that part! This sounds familiar - I think we had an issue with magic links on Safari before. #186

smoothdvd commented 2 weeks ago

I found TRIGGER_PROTOCOL env not working when I set WEBAPP_PUBLISH_IP=192.168.1.x. It still runs on local , but magic link always generate https link even set TRIGGER_PROTOCOL=http.

nicktrn commented 2 weeks ago

I don't think that WEBAPP_PUBLISH_IP should change anything, but it's possible that TRIGGER_PROTOCOL is being ignored. Is this the full or split setup? Also, when changing any env vars, make sure to restart all services. ./stop.sh && ./start.sh should do it.

smoothdvd commented 2 weeks ago

@nicktrn I use the full setup to self-host Trigger.dev on a home server. I set WEBAPP_PUBLISH_IP=192.168.1.x to allow another client PC to access it via http://192.168.1.x:3040.

nicktrn commented 2 weeks ago

I found TRIGGER_PROTOCOL env not working when I set WEBAPP_PUBLISH_IP=192.168.1.x. It still runs on local , but magic link always generate https link even set TRIGGER_PROTOCOL=http.

Okay, I tracked this down to the external package we're using for magic link auth. It sets the protocol to "https" unless you're accessing the webapp via "localhost" or "127.0.0.1".

image

I don't see us changing this because it's very niche.

You could solve both problems quite easily if you're only accessing the webapp locally and have no need to secure logins. Setting NODE_ENV=development in your .env will disable magic link auth and log you in automatically.

An alternative would be to access the webapp only via the external domain, even when accessing on your local network.

smoothdvd commented 2 weeks ago

@nicktrn Thank you for help!