mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
feat: Working version with google drive storage.
This commit is contained in:
@@ -1,31 +1,23 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { google } from "googleapis";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const url = new URL(request.url);
|
||||
const code = url.searchParams.get("code");
|
||||
const clientId = url.searchParams.get("clientId");
|
||||
const clientSecret = url.searchParams.get("clientSecret");
|
||||
const redirectUri = url.searchParams.get("redirectUri");
|
||||
const url = new URL(request.url);
|
||||
const code = url.searchParams.get("code");
|
||||
|
||||
if (!code || !clientId || !clientSecret || !redirectUri) {
|
||||
return NextResponse.json({ error: "Missing parameters" }, { status: 400 });
|
||||
const success = Boolean(code);
|
||||
|
||||
return new Response(
|
||||
`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<h1>${success ? "Success" : "Failed"}</h1>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
{
|
||||
status: success ? 200 : 400,
|
||||
headers: {
|
||||
"Content-Type": "text/html; charset=utf-8",
|
||||
},
|
||||
}
|
||||
|
||||
try {
|
||||
const oauth2Client = new google.auth.OAuth2(clientId, clientSecret, redirectUri);
|
||||
const { tokens } = await oauth2Client.getToken(code);
|
||||
|
||||
// Save tokens.refresh_token securely in your DB here
|
||||
|
||||
return NextResponse.json(tokens);
|
||||
} catch (err: any) {
|
||||
console.error("Error exchanging code:", err);
|
||||
return NextResponse.json({ error: "Failed to exchange code" }, { status: 500 });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error in GET handler:", error);
|
||||
return NextResponse.json({ error: "Internal server error" }, { status: 500 });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user