This project is a simple reverse proxy built using Flask and Requests. It serves as an example to help developers set up Supabase authentication across subdomains. It is intended for development purposes only.
This project is entirely based on the supbase auth nextjs starter template. Supabase Auth Next.js Starter Template
To get started, you'll need to install the necessary dependencies.
pip install flask requests
npm install
sudo nano /etc/hosts
Add the following lines:
# root domain name does not matter, you can set it to anything you want
# but has to be the same for both subdomains. www.digglywumpus.com works
# just as well as www.auth-learn.com. middleware.ts adn server.ts in utils/supabase
# must be udpated to match the domain named in the hosts file.
127.0.0.1 www.auth-learn.com
127.0.0.1 app.auth-learn.com
nano .env.local # see .env.example for reference
python proxy.py # must be run by root user and must be python3
npm run www # for the first subdomain
# In a new terminal
npm run app # for the second subdomain
- Open a browser page and navigate to http://www.auth-learn.com
- Sign in to the app, you should be redirected to http://www.auth-learn.com/protected
- Inspect the cookies, you should see a
sb-<supabase-project-id>-auth-token
cookie. - Navigate to http://app.auth-learn.com/protected
- Your auth status on the www subdomain should be shared with the app subdomain.
- Signout on either subdomain will sign you out of both.
Main change was made to the supabase auth nextjs starter template:
- The following changes were made to
middleware.ts
andserver.ts
in theutils/supabase
directory:
@@ -16,6 +16,14 @@ export const updateSession = async (request: NextRequest) => {
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
+ cookieOptions: { // 👈 Add this
+ domain: '.auth-learn.com', // Allow auth-learn.com and all subdomains
+ secure: false,
+ sameSite: 'lax',
+ path: '/',
+ maxAge: 60 * 60 * 24 * 30,
+ httpOnly: true,
+ },
cookies: {
getAll() {
return request.cookies.getAll();
I created a video walkhrough a live demo of this project here.