@@ -4,12 +4,28 @@ import { useState, useEffect } from "react"
44import { useRouter } from "next/navigation"
55import { supabaseClient } from "../../lib/supabaseClient"
66import { updateProfileCache } from "../../lib/profileCache"
7+ import { siteConfig } from "../siteConfig"
78import { PotionBackground } from "../components/PotionBackground"
89import { Button } from "../components/Button"
910import { PageContainer } from "../components/PageContainer"
1011import { TextInput } from "../components/TextInput"
1112import { SuccessMessage } from "../components/SuccessMessage"
1213
14+ // Helper function to get the base URL for OAuth redirects
15+ // Uses production URL (devx.network) in production, localhost in development
16+ const getBaseUrl = ( ) => {
17+ if ( typeof window === "undefined" ) {
18+ return siteConfig . url
19+ }
20+ const hostname = window . location . hostname
21+ // Use localhost origin for local development
22+ if ( hostname === "localhost" || hostname === "127.0.0.1" || hostname . startsWith ( "192.168." ) ) {
23+ return window . location . origin
24+ }
25+ // Use production URL for all other cases
26+ return siteConfig . url
27+ }
28+
1329export default function Login ( ) {
1430 const [ error , setError ] = useState < string | null > ( null )
1531 const [ email , setEmail ] = useState ( "" )
@@ -94,9 +110,10 @@ export default function Login() {
94110 }
95111
96112 // Include redirect in the OAuth callback URL
113+ const baseUrl = getBaseUrl ( )
97114 const loginUrl = redirectUrl
98- ? `${ window . location . origin } /login?redirect=${ encodeURIComponent ( redirectUrl ) } `
99- : `${ window . location . origin } /login`
115+ ? `${ baseUrl } /login?redirect=${ encodeURIComponent ( redirectUrl ) } `
116+ : `${ baseUrl } /login`
100117
101118 const { error } = await supabaseClient ! . auth . signInWithOAuth ( {
102119 provider,
@@ -176,13 +193,14 @@ export default function Login() {
176193 const redirectUrl = searchParams . get ( "redirect" )
177194
178195 // Sign up with email and password
196+ const baseUrl = getBaseUrl ( )
179197 const { data, error : signUpError } = await supabaseClient . auth . signUp ( {
180198 email,
181199 password,
182200 options : {
183201 emailRedirectTo : redirectUrl
184- ? `${ window . location . origin } /setup?redirect=${ encodeURIComponent ( redirectUrl ) } `
185- : `${ window . location . origin } /setup`
202+ ? `${ baseUrl } /setup?redirect=${ encodeURIComponent ( redirectUrl ) } `
203+ : `${ baseUrl } /setup`
186204 }
187205 } )
188206
0 commit comments