Google OAuth issue in Production Railway React app
vemaya-asia
HOBBYOP

6 months ago

Hello,

I have the changents.ai app deployed in production railway. The Goole social login click in production takes some time and redirect to an error page. I have attached the architecture app railway configuration and the Google OAuth config too for you to help me fixing this issue, as i have tried several attempts still not able to resolve. The app is deployed using docker file where by the backend running (local) with port 8084 and front end (local) with port 8085. I have tried changing this to 443 but app went not reachable. Attached the screenshots for reference and let me know for any questions. Thanks in advance

Ramya

Attachments

$10 Bounty

6 Replies

Railway
BOT

6 months ago


6 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 6 months ago


Railway

Hey there! We've found the following might help you get unblocked faster: - [🧵 Error while connecting Google OAuth 2.0 Client IDs](https://station.railway.com/questions/error-while-connecting-google-o-auth-2-0-f0008dc4) - [🧵 Google Drive API OAuth Redirect Issue on n8n](https://station.railway.com/questions/bug-report-google-drive-api-o-auth-redir-10e36397) - [🧵 [Help] Django Google OAuth - Works locally but fails in prod with "django_session does not exist"](https://station.railway.com/questions/help-django-google-o-auth-works-local-38a9e3a7) - [🧵 Github integration issue](https://station.railway.com/questions/github-integration-issue-ae8a95ee) If you find the answer from one of these, please let us know by solving the thread!

vemaya-asia
HOBBYOP

6 months ago

No none of these working


6 months ago

Can't zoom in to your ENV. Please check if you're using localhost as the redirect URL and if that the case replace with the railway production url. If you have assigned it with values in env, try updating manually


6 months ago

Also if you already connected to a domain, the redirect url need to be in the same domain. Not the default "PROJECT_NAME.up.railway.app"


iiiixi

Can't zoom in to your ENV. Please check if you're using localhost as the redirect URL and if that the case replace with the railway production url. If you have assigned it with values in env, try updating manually

vemaya-asia
HOBBYOP

6 months ago

Nope, I am not using localhost. Its the original custom domain validated ( htpps://myowndomain/api/auth/google/callback) is my GOOGLE_CALLBACK_URL and google redirect uri i have configured still not working. Thanks for your help.


cflexdeveandcompanymain
PRO

6 months ago

You were detailed enough with the screenshort and i observed that....

  1. Redirect URIs mismatch,

  2. Authorized JavaScript Origins mismatch,

  3. Backend/Frontend port issue....

    to fix this ..

    1. for Backend (Dockerfile)

      i. Use Python base image (adjust if you use Node, Go, etc.)

FROM python:3.11-slim

ii. Set working dir

WORKDIR /app

iii. Install dependencies

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

iv. Copy code

COPY . .

v. Railway assigns a dynamic $PORT

EXPOSE 8080

vi. Run app (adjust entrypoint if needed)

CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-8080}"]

(COPY)

  1. for Backend .env.production

# Google OAuth credentials

GOOGLE_CLIENT_ID=xxxxxxxx.apps.googleusercontent.com

GOOGLE_CLIENT_SECRET=xxxxxxxx

GOOGLE_REDIRECT_URI=https://changents.ai/api/v1/google/callback

# Railway sets PORT automatically, don’t hardcode 8084 or 443

2. for Frontend .env.production

NEXT_PUBLIC_API_BASE_URL=https://changents.ai/api/v1

NEXT_PUBLIC_GOOGLE_CLIENT_ID=xxxxxxxx.apps.googleusercontent.com

NEXT_PUBLIC_GOOGLE_REDIRECT_URI=https://changents.ai/api/v1/google/callback

  1. Frontend OAuth Request (React/Next.js)

const googleAuthUrl = https://accounts.google.com/o/oauth2/v2/auth?client_id=${process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI}&response_type=code&scope=openid%20email%20profile&access_type=offline;

const handleGoogleLogin = () => {

window.location.href = googleAuthUrl;

};

Take Note

Google Cloud Console (must match exactly)

https://changents.ai

this helps to Authorized JavaScript origins

-Authorized redirect URIs

https://changents.ai/api/v1/google/callback

(Add http://localhost:8084/api/v1/google/callback only for local testing)


Loading...