55import { NextRequest , NextResponse } from 'next/server' ;
66
77export async function GET ( req : NextRequest ) {
8- try {
9- const { searchParams } = new URL ( req . url ) ;
10- const code = searchParams . get ( 'code' ) ;
11- const state = searchParams . get ( 'state' ) ;
12- const error = searchParams . get ( 'error' ) ;
13-
14- // Handle OAuth error
15- if ( error ) {
16- console . error ( 'GitHub OAuth error:' , error ) ;
17- return NextResponse . redirect ( new URL ( '/login?error=oauth_error' , req . url ) ) ;
18- }
19-
20- // Validate required parameters
21- if ( ! code ) {
22- console . error ( 'GitHub OAuth: No authorization code received' ) ;
23- return NextResponse . redirect ( new URL ( '/login?error=oauth_invalid' , req . url ) ) ;
24- }
25-
26- // Dynamic import to keep server-only
27- const { SSOService, AuthService } = await import ( '@codervisor/devlog-core/auth' ) ;
28-
29- const ssoService = SSOService . getInstance ( ) ;
30- const authService = AuthService . getInstance ( ) ;
31-
32- // Exchange code for user info
33- const ssoUserInfo = await ssoService . exchangeCodeForUser ( 'github' , code , state || undefined ) ;
34-
35- // Handle SSO login/registration
36- const authResponse = await authService . handleSSOLogin ( ssoUserInfo ) ;
37-
38- // Parse return URL from state
39- let returnUrl = '/projects' ;
40- if ( state ) {
41- try {
42- const stateData = JSON . parse ( Buffer . from ( state , 'base64' ) . toString ( ) ) ;
43- if ( stateData . returnUrl ) {
44- returnUrl = stateData . returnUrl ;
45- }
46- } catch ( error ) {
47- console . warn ( 'Failed to parse state:' , error ) ;
48- }
49- }
50-
51- // Create response with tokens
52- const response = NextResponse . redirect ( new URL ( returnUrl , req . url ) ) ;
53-
54- // Set HTTP-only cookies for security
55- response . cookies . set ( 'accessToken' , authResponse . tokens . accessToken , {
56- httpOnly : true ,
57- secure : process . env . NODE_ENV === 'production' ,
58- sameSite : 'lax' ,
59- maxAge : 15 * 60 , // 15 minutes
60- path : '/' ,
61- } ) ;
62-
63- response . cookies . set ( 'refreshToken' , authResponse . tokens . refreshToken , {
64- httpOnly : true ,
65- secure : process . env . NODE_ENV === 'production' ,
66- sameSite : 'lax' ,
67- maxAge : 7 * 24 * 60 * 60 , // 7 days
68- path : '/' ,
69- } ) ;
70-
71- return response ;
72-
73- } catch ( error ) {
74- console . error ( 'GitHub OAuth callback error:' , error ) ;
75-
76- if ( error instanceof Error ) {
77- if ( error . message . includes ( 'not configured' ) ) {
78- return NextResponse . redirect ( new URL ( '/login?error=oauth_not_configured' , req . url ) ) ;
79- }
80- if ( error . message . includes ( 'No email' ) ) {
81- return NextResponse . redirect ( new URL ( '/login?error=oauth_no_email' , req . url ) ) ;
82- }
83- }
84-
85- return NextResponse . redirect ( new URL ( '/login?error=oauth_failed' , req . url ) ) ;
86- }
8+ // SSO functionality temporarily disabled during Prisma migration
9+ console . log ( 'GitHub OAuth callback temporarily disabled during migration' ) ;
10+ return NextResponse . redirect ( new URL ( '/login?error=sso_disabled' , req . url ) ) ;
8711}
0 commit comments