feat: integrate authentication and password management features, including bcrypt for hashing and NextAuth for session handling
This commit is contained in:
21
lib/auth-utils.ts
Normal file
21
lib/auth-utils.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
/**
|
||||
* Verify that the user is authenticated
|
||||
* Returns null if authenticated, or a NextResponse with 401 if not
|
||||
*/
|
||||
export async function requireAuth(): Promise<NextResponse | null> {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session) {
|
||||
return NextResponse.json(
|
||||
{ error: "Non authentifié" },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user