Skip to content

Commit b767057

Browse files
amitsingh-007claude
andcommitted
feat(web): support HTTPS local dev for redirect sign-in
Add a `dev:https` script and, when dev runs over https, set authDomain to the current origin so signInWithRedirect stays same-origin via the /__/auth proxy (Firebase forces https://<authDomain>/__/auth/handler). Make the proxy target env-aware so dev proxies to the dev Firebase project. Default http `pnpm dev` and e2e are unaffected. Requires https://localhost:3000/__/auth/handler on the dev OAuth client. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e805871 commit b767057

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

apps/web/next.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ const nextConfig: NextConfig = {
4343
// flow. Must be a transparent proxy (rewrite), not a 302.
4444
// https://firebase.google.com/docs/auth/web/redirect-best-practices
4545
async rewrites() {
46-
const authHelper = 'https://bypass-links.firebaseapp.com';
46+
// Match the Firebase project that getFirebasePublicConfig selects by env.
47+
const authHelper = isDev
48+
? 'https://bypass-links-dev.firebaseapp.com'
49+
: 'https://bypass-links.firebaseapp.com';
4750
return [
4851
{
4952
source: '/__/auth/:path*',

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"build": "next build --webpack",
88
"dev": "next dev --webpack",
9+
"dev:https": "next dev --webpack --experimental-https",
910
"typecheck": "tsc --noEmit"
1011
},
1112
"dependencies": {
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import { getFirebasePublicConfig } from '@bypass/configs/firebase.config';
22
import { initializeApp } from 'firebase/app';
33

4-
const firebaseApp = initializeApp(
5-
getFirebasePublicConfig(process.env.NODE_ENV === 'production')
6-
);
4+
const isProd = process.env.NODE_ENV === 'production';
5+
const config = getFirebasePublicConfig(isProd);
6+
7+
// In HTTPS local dev (`pnpm dev:https`), point authDomain at our own origin so
8+
// signInWithRedirect stays same-origin via the /__/auth proxy in next.config —
9+
// Firebase always builds the handler URL as `https://<authDomain>/__/auth/...`,
10+
// so this only works over https, not the default http `pnpm dev`.
11+
if (
12+
!isProd &&
13+
typeof window !== 'undefined' &&
14+
window.location.protocol === 'https:'
15+
) {
16+
config.authDomain = window.location.host;
17+
}
18+
19+
const firebaseApp = initializeApp(config);
720

821
export default firebaseApp;

0 commit comments

Comments
 (0)