@@ -2,8 +2,8 @@ import { redirect } from 'next/navigation'
22import { Suspense } from 'react'
33import { AUTH_URLS , PROTECTED_URLS } from '@/configs/urls'
44import { createUserTeamsRepository } from '@/core/modules/teams/user-teams-repository.server'
5+ import { auth } from '@/core/server/auth'
56import { l , serializeErrorForLog } from '@/core/shared/clients/logger/logger'
6- import { createClient } from '@/core/shared/clients/supabase/server'
77import { encodedRedirect } from '@/lib/utils/auth'
88import { generateE2BUserAccessToken } from '@/lib/utils/server'
99import { Alert , AlertDescription , AlertTitle } from '@/ui/primitives/alert'
@@ -96,11 +96,7 @@ export default async function CLIAuthPage({
9696 searchParams : CLISearchParams
9797} ) {
9898 const { next, state, error } = await searchParams
99- const supabase = await createClient ( )
100-
101- const {
102- data : { user } ,
103- } = await supabase . auth . getUser ( )
99+ const authContext = await auth . getAuthContext ( )
104100
105101 if ( state === 'success' ) {
106102 return < SuccessState />
@@ -111,7 +107,7 @@ export default async function CLIAuthPage({
111107 l . error (
112108 {
113109 key : 'cli_auth:invalid_redirect_url' ,
114- user_id : user ? .id ,
110+ user_id : authContext ?. user . id ,
115111 context : {
116112 next,
117113 } ,
@@ -122,29 +118,25 @@ export default async function CLIAuthPage({
122118 }
123119
124120 // If user is not authenticated, redirect to sign in with return URL
125- if ( ! user ) {
121+ if ( ! authContext ) {
126122 const searchParams = new URLSearchParams ( {
127123 returnTo : `${ AUTH_URLS . CLI } ?${ new URLSearchParams ( { next } ) . toString ( ) } ` ,
128124 } )
129125 redirect ( `${ AUTH_URLS . SIGN_IN } ?${ searchParams . toString ( ) } ` )
130126 }
131127
132128 // Handle CLI callback if authenticated
133- if ( ! error && next && user ) {
129+ if ( ! error && next && authContext ) {
134130 try {
135- const {
136- data : { session } ,
137- } = await supabase . auth . getSession ( )
138-
139- if ( ! session ?. access_token ) {
140- throw new Error ( 'No provider access token found' )
141- }
142-
143- if ( ! user . email ) {
131+ if ( ! authContext . user . email ) {
144132 throw new Error ( 'No user email found' )
145133 }
146134
147- return await handleCLIAuth ( next , user . email , session . access_token )
135+ return await handleCLIAuth (
136+ next ,
137+ authContext . user . email ,
138+ authContext . accessToken
139+ )
148140 } catch ( err ) {
149141 if ( err instanceof Error && err . message . includes ( 'NEXT_REDIRECT' ) ) {
150142 throw err
@@ -154,7 +146,7 @@ export default async function CLIAuthPage({
154146 {
155147 key : 'cli_auth:unexpected_error' ,
156148 error : serializeErrorForLog ( err ) ,
157- user_id : user ? .id ,
149+ user_id : authContext . user . id ,
158150 context : {
159151 next,
160152 } ,
0 commit comments