forked from ky28059/bctf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server-side login via handler, fix build error (again)
- Loading branch information
Showing
3 changed files
with
35 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { login } from '@/util/auth'; | ||
|
||
|
||
export async function GET(req: NextRequest) { | ||
const params = req.nextUrl.searchParams; | ||
|
||
const token = params.get('token'); | ||
if (!token) | ||
return NextResponse.redirect(new URL('/login', req.url)); | ||
|
||
const res = await login(token); | ||
if ('error' in res) | ||
return NextResponse.redirect(new URL(`/login?error=${res.error}`, req.url)); | ||
|
||
return NextResponse.redirect(new URL('/profile', req.url)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import type { Metadata } from 'next'; | ||
import { redirect } from 'next/navigation'; | ||
|
||
// Components | ||
import LoginContent from '@/app/login/LoginContent'; | ||
|
||
|
||
export const metadata: Metadata = { | ||
title: 'Log in' | ||
} | ||
|
||
export default function Login() { | ||
export default async function Login({ searchParams }: { searchParams: Promise<{ token?: string, error?: string }> }) { | ||
const token = (await searchParams).token; | ||
const error = (await searchParams).error; | ||
|
||
// Automatically sign in if the `token` search parameter is set. | ||
if (token) return redirect(`/login-handler?token=${token}`) | ||
|
||
return ( | ||
<div className="container pt-32 pb-24"> | ||
<h1 className="text-2xl font-bold mb-8 text-center"> | ||
Log in to b01lers CTF | ||
</h1> | ||
|
||
<LoginContent /> | ||
<LoginContent error={error} /> | ||
</div> | ||
) | ||
} |