@@ -4,6 +4,7 @@ import { useEffect, Suspense } from "react";
44import { useRouter , useSearchParams } from "next/navigation" ;
55import { createClient } from "@/lib/supabase/client" ;
66import { toast } from "sonner" ;
7+ import { profileService } from "@/lib/services/profile" ;
78
89function OAuthCallbackContent ( ) {
910 const router = useRouter ( ) ;
@@ -38,19 +39,18 @@ function OAuthCallbackContent() {
3839 . single ( ) ;
3940
4041 if ( ! profile ) {
41- // Create profile for OAuth user
42- const provider = session . user . app_metadata ?. provider || 'google' ;
43- await supabase . rpc ( 'create_oauth_profile' , {
44- user_id : session . user . id ,
45- email : session . user . email || '' ,
46- auth_provider : provider ,
47- user_metadata : session . user . user_metadata || { }
48- } ) ;
49-
50- // After creating profile, redirect to complete profile
51- console . log ( 'Profile created, redirecting to complete profile' ) ;
52- router . replace ( '/complete-profile' ) ;
53- return ;
42+ // Create profile for OAuth user using profileService
43+ try {
44+ await profileService . getProfile ( session . user . id ) ;
45+ console . log ( 'Profile created via profileService, redirecting to complete profile' ) ;
46+ router . replace ( '/complete-profile' ) ;
47+ return ;
48+ } catch ( profileError ) {
49+ console . error ( 'Error creating profile:' , profileError ) ;
50+ // Continue to complete profile page anyway
51+ router . replace ( '/complete-profile' ) ;
52+ return ;
53+ }
5454 }
5555
5656 // Check if profile is complete (has first_name, last_name, and username)
@@ -115,19 +115,18 @@ function OAuthCallbackContent() {
115115 . single ( ) ;
116116
117117 if ( ! profile ) {
118- // Create profile for OAuth user
119- const provider = retrySession . user . app_metadata ?. provider || 'google' ;
120- await supabase . rpc ( 'create_oauth_profile' , {
121- user_id : retrySession . user . id ,
122- email : retrySession . user . email || '' ,
123- auth_provider : provider ,
124- user_metadata : retrySession . user . user_metadata || { }
125- } ) ;
126-
127- // After creating profile, redirect to complete profile
128- console . log ( 'Profile created on retry, redirecting to complete profile' ) ;
129- router . replace ( '/complete-profile' ) ;
130- return ;
118+ // Create profile for OAuth user using profileService
119+ try {
120+ await profileService . getProfile ( retrySession . user . id ) ;
121+ console . log ( 'Profile created via profileService on retry, redirecting to complete profile' ) ;
122+ router . replace ( '/complete-profile' ) ;
123+ return ;
124+ } catch ( profileError ) {
125+ console . error ( 'Error creating profile on retry:' , profileError ) ;
126+ // Continue to complete profile page anyway
127+ router . replace ( '/complete-profile' ) ;
128+ return ;
129+ }
131130 }
132131
133132 // Check if profile is complete (has first_name, last_name, and username)
@@ -167,19 +166,18 @@ function OAuthCallbackContent() {
167166 . single ( ) ;
168167
169168 if ( ! profile ) {
170- // Create profile for OAuth user
171- const provider = finalSession . user . app_metadata ?. provider || 'google' ;
172- await supabase . rpc ( 'create_oauth_profile' , {
173- user_id : finalSession . user . id ,
174- email : finalSession . user . email || '' ,
175- auth_provider : provider ,
176- user_metadata : finalSession . user . user_metadata || { }
177- } ) ;
178-
179- // After creating profile, redirect to complete profile
180- console . log ( 'Profile created on final try, redirecting to complete profile' ) ;
181- router . replace ( '/complete-profile' ) ;
182- return ;
169+ // Create profile for OAuth user using profileService
170+ try {
171+ await profileService . getProfile ( finalSession . user . id ) ;
172+ console . log ( 'Profile created via profileService on final try, redirecting to complete profile' ) ;
173+ router . replace ( '/complete-profile' ) ;
174+ return ;
175+ } catch ( profileError ) {
176+ console . error ( 'Error creating profile on final try:' , profileError ) ;
177+ // Continue to complete profile page anyway
178+ router . replace ( '/complete-profile' ) ;
179+ return ;
180+ }
183181 }
184182
185183 // Check if profile is complete (has first_name, last_name, and username)
0 commit comments