33import Image from "next/image" ;
44import { useRouter } from "next/navigation" ;
55import { useEffect , useState } from "react" ;
6- import { env } from "@/env " ;
6+ import { client } from "@/lib/client " ;
77
88export default function AuthCallback ( ) {
99 const router = useRouter ( ) ;
@@ -40,22 +40,22 @@ export default function AuthCallback() {
4040 return ;
4141 }
4242
43- // Send tokens to backend
44- const response = await fetch ( `${ env . NEXT_PUBLIC_BACKEND_URL } /api/auth/callback` , {
45- method : "POST" ,
46- headers : {
47- "Content-Type" : "application/json" ,
48- } ,
49- body : JSON . stringify ( {
43+ const response = await client . api . auth . callback . post (
44+ {
5045 access_token : accessToken ,
5146 refresh_token : refreshToken ,
52- } ) ,
53- credentials : "include" , // Important for cookies
54- } ) ;
47+ } ,
48+ {
49+ headers : {
50+ "Content-Type" : "application/json" ,
51+ credentials : "include" ,
52+ } ,
53+ }
54+ ) ;
5555
56- const result = await response . json ( ) ;
56+ const result = response . data ;
5757
58- if ( response . ok && result . success ) {
58+ if ( response . status === 200 && result ?. user ) {
5959 setStatus ( "success" ) ;
6060 setMessage ( "Authentication successful!" ) ;
6161 setUserInfo ( result . user ) ;
@@ -68,11 +68,11 @@ export default function AuthCallback() {
6868
6969 // Redirect to your desired page after a delay
7070 setTimeout ( ( ) => {
71- router . push ( "/test " ) ;
71+ router . push ( "/dashboard " ) ;
7272 } , 3000 ) ;
7373 } else {
7474 setStatus ( "error" ) ;
75- setMessage ( result . error || "Authentication failed" ) ;
75+ setMessage ( response . error ?. value ?. summary || "Authentication failed" ) ;
7676 }
7777 } catch ( error ) {
7878 console . error ( "Auth callback error:" , error ) ;
0 commit comments