File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 22
33import { redirect } from "next/navigation" ;
44import { createClient } from "./server" ;
5- import { headers } from "next/headers" ;
5+
6+ // 1. Create a helper to get the REAL base URL
7+ const getURL = ( ) => {
8+ let url = process . env . NEXT_PUBLIC_SITE_URL ?? process . env . VERCEL_URL ?? "http://localhost:3000" ;
9+
10+ url = url . includes ( "http" ) ? url : `https://${ url } ` ;
11+ url = url . replace ( / \/ $ / , "" ) ;
12+ return url ;
13+ } ;
14+
615export default async function handleOAuthLogin ( provider : "github" | "google" ) {
716 const supabase = await createClient ( ) ;
8- const headersList = await headers ( ) ;
9- const origin = headersList . get ( "origin" ) ?? `https://${ headersList . get ( "host" ) } ` ; ;
17+ const origin = getURL ( ) ;
1018 const { error, data } = await supabase . auth . signInWithOAuth ( {
1119 provider : provider ,
12- options : { redirectTo : `${ origin } /auth/callback?next=/dashboard` } ,
20+ options : {
21+ redirectTo : `${ origin } /auth/callback?next=/dashboard` ,
22+ } ,
1323 } ) ;
1424
1525 if ( error ) throw error ;
You can’t perform that action at this time.
0 commit comments