Skip to content

Commit

Permalink
(hopefully) fixed redirects!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
n1kPLV committed Jul 26, 2023
1 parent 652388a commit 6d4a647
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Website/src/app/webapi/auth/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ import {cookies} from "next/headers";
import {NextRequest, NextResponse} from "next/server";
import {authenticate} from "@/lib/data";
import {NextURL} from "next/dist/server/web/next-url";
import {hostname} from "os";

// export async function GET(request: NextRequest) {
// return new NextResponse(null, { status: 405 })
// }

export async function POST(request: NextRequest) {
const url = request.nextUrl.clone();
const base_host = request.headers.get('x-forwarded-host')
const base_host = request.headers.get('origin')

console.log('request headers:', request.headers);
// console.log('request headers:', request.headers);
const url = new NextURL('/', base_host ?? `http://${hostname()}`);

// console.log('baz', request.destination);
const data = await request.formData();
// console.log('foo', data);
url.pathname = data.get("dst_url")?.toString() || '/';
// console.log("new url", url)

const username = data.get("username")?.toString()
const password = data.get("password")?.toString()
if (username && password) {
Expand All @@ -30,7 +29,7 @@ export async function POST(request: NextRequest) {
sameSite: 'lax',
httpOnly: true
});
url.searchParams.set('success', 'true')
url.searchParams.set('success', 'true');
console.log("User:", username, 'login successful.');
} else {
console.log("User:", username, 'login failed.');
Expand All @@ -44,5 +43,5 @@ export async function POST(request: NextRequest) {
return new NextResponse('Malformed Request', {status: 400});
}

return NextResponse.redirect(new NextURL(url, {base: base_host ?? undefined}))
return NextResponse.redirect(url);
}

0 comments on commit 6d4a647

Please sign in to comment.