Skip to content

Commit 09265b9

Browse files
Copilottikazyq
andcommitted
Complete TypeORM legacy removal - transition to Prisma-only architecture
Co-authored-by: tikazyq <[email protected]>
1 parent d35aab3 commit 09265b9

File tree

21 files changed

+74
-840
lines changed

21 files changed

+74
-840
lines changed

apps/web/app/api/auth/callback/github/route.ts

Lines changed: 3 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,7 @@
55
import { NextRequest, NextResponse } from 'next/server';
66

77
export 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
}

apps/web/app/api/auth/callback/google/route.ts

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,7 @@
55
import { NextRequest, NextResponse } from 'next/server';
66

77
export 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('Google 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('Google 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('google', 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('Google 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-
}
81-
82-
return NextResponse.redirect(new URL('/login?error=oauth_failed', req.url));
83-
}
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));
8411
}

apps/web/app/api/auth/callback/wechat/route.ts

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,7 @@
55
import { NextRequest, NextResponse } from 'next/server';
66

77
export 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('WeChat 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('WeChat 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('wechat', 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('WeChat 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-
}
81-
82-
return NextResponse.redirect(new URL('/login?error=oauth_failed', req.url));
83-
}
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));
8411
}

apps/web/app/api/auth/me/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ export async function GET(req: NextRequest) {
1616
const token = authHeader.substring(7); // Remove 'Bearer ' prefix
1717

1818
// Dynamic import to keep server-only
19-
const { AuthService } = await import('@codervisor/devlog-core/auth');
20-
const authService = AuthService.getInstance();
19+
const { PrismaAuthService } = await import('@codervisor/devlog-core/auth');
20+
const authService = PrismaAuthService.getInstance();
21+
await authService.initialize();
2122

22-
const user = await authService.verifyToken(token);
23+
const user = await authService.validateToken(token);
2324

2425
return NextResponse.json({
2526
success: true,

apps/web/app/api/auth/refresh/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export async function POST(req: NextRequest) {
1515
const validatedData = refreshSchema.parse(body);
1616

1717
// Dynamic import to keep server-only
18-
const { AuthService } = await import('@codervisor/devlog-core/auth');
19-
const authService = AuthService.getInstance();
18+
const { PrismaAuthService } = await import('@codervisor/devlog-core/auth');
19+
const authService = PrismaAuthService.getInstance();
2020
const newTokens = await authService.refreshToken(validatedData.refreshToken);
2121

2222
return NextResponse.json({

apps/web/app/api/auth/reset-password/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export async function POST(req: NextRequest) {
2121
const action = searchParams.get('action');
2222

2323
// Dynamic import to keep server-only
24-
const { AuthService } = await import('@codervisor/devlog-core/auth');
25-
const authService = AuthService.getInstance();
24+
const { PrismaAuthService } = await import('@codervisor/devlog-core/auth');
25+
const authService = PrismaAuthService.getInstance();
2626

2727
if (action === 'request') {
2828
const validatedData = requestResetSchema.parse(body);

apps/web/app/api/auth/verify-email/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export async function POST(req: NextRequest) {
1515
const validatedData = verifyEmailSchema.parse(body);
1616

1717
// Dynamic import to keep server-only
18-
const { AuthService } = await import('@codervisor/devlog-core/auth');
19-
const authService = AuthService.getInstance();
18+
const { PrismaAuthService } = await import('@codervisor/devlog-core/auth');
19+
const authService = PrismaAuthService.getInstance();
2020
const user = await authService.verifyEmail(validatedData.token);
2121

2222
return NextResponse.json({

0 commit comments

Comments
 (0)