Supabase Auth (which is based on GoTrue) does not allow you to directly set the session's IP address via the X-Forwarded-For header from the client side. However, it does use the X-Forwarded-For header if present when determining the user's IP address for things like logging, rate limiting, and security checks.
How it works
- When a request hits the Supabase Auth API (e.g.,
/auth/v1/token), the backend will look for the X-Forwarded-For header.
- If your Supabase project is behind a proxy (like Cloudflare, Vercel, or your own Nginx), that proxy should set the
X-Forwarded-For header to the original client IP.
- Supabase Auth will then use the first IP in the
X-Forwarded-For list as the user's IP address.
You cannot set this header from the browser
Browsers do not allow you to set the X-Forwarded-For header via JavaScript or fetch requests for security reasons. Only a trusted proxy (like your own backend or a CDN) can set this header.
How to set the IP address for Supabase Auth
1. If you control the proxy (e.g., Nginx, Cloudflare Worker, Vercel Edge):
- Ensure your proxy sets the
X-Forwarded-For header to the real client IP.
- Supabase Auth will use this value.
2. If you want to spoof the IP (for testing, etc.):
3. On Supabase Edge Functions:
Summary Table
| Scenario | Can set X-Forwarded-For? | Will Supabase use it? |
|---|
| Browser/Frontend | ❌ | N/A |
| Your backend/proxy | ✅ | ✅ |
| Supabase Edge Functions | ✅ | ✅ |
In short:
- You cannot set the session's IP from the browser.
- You can set it from a backend or proxy by setting the
X-Forwarded-For header.
- Supabase Auth will use the first IP in that header as the user's IP.
References:
If you have a specific use case (e.g., testing, logging, etc.), let me know and I can provide a more tailored example!