Move to next-auth
This commit is contained in:
parent
3b8bb9dea4
commit
a46b2ac3c6
10 changed files with 107 additions and 20 deletions
26
auth.ts
Normal file
26
auth.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import NextAuth from "@auth/nextjs";
|
||||
import GitHub from "@auth/nextjs/providers/github";
|
||||
import { NextResponse } from "next/server";
|
||||
export const {
|
||||
handlers: { GET, POST },
|
||||
auth,
|
||||
CSRF_experimental,
|
||||
} = NextAuth({
|
||||
// @ts-ignore
|
||||
providers: [GitHub],
|
||||
session: { strategy: "jwt" },
|
||||
async authorized({ request, auth }: any) {
|
||||
const url = request.nextUrl;
|
||||
|
||||
if (request.method === "POST") {
|
||||
const { authToken } = (await request.json()) ?? {};
|
||||
// If the request has a valid auth token, it is authorized
|
||||
const valid = true;
|
||||
if (valid) return true;
|
||||
return NextResponse.json("Invalid auth token", { status: 401 });
|
||||
}
|
||||
|
||||
// Logged in users are authenticated, otherwise redirect to login page
|
||||
return !!auth;
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue