fixed the auth issue
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
import axios from "axios";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { cookies } from "next/headers";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const code = searchParams.get("code");
|
||||
|
||||
console.log(request.url, request.nextUrl);
|
||||
|
||||
if (!code) {
|
||||
return NextResponse.json(
|
||||
{ error: "No code provided" },
|
||||
{ status: StatusCodes.BAD_REQUEST }
|
||||
{ status: StatusCodes.BAD_REQUEST },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,7 +28,7 @@ export async function GET(request: Request) {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const accessToken = response.data.access_token;
|
||||
@@ -38,12 +40,12 @@ export async function GET(request: Request) {
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
});
|
||||
|
||||
return NextResponse.redirect(new URL("/overview", request.url));
|
||||
return NextResponse.redirect(`${request.nextUrl.origin}/overview`);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return NextResponse.json(
|
||||
{ error: "Error exchanging code for access token" },
|
||||
{ status: StatusCodes.INTERNAL_SERVER_ERROR }
|
||||
{ status: StatusCodes.INTERNAL_SERVER_ERROR },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user