#middleware origin and auth bugged / not working

11 messages · Page 1 of 1 (latest)

pine bane
#
import { NextResponse } from "next/server";
 
// export { default } from "next-auth/middleware";
 
const allowedOrigins =
  process.env.NODE_ENV === "production"
    ? ["https://www.yoursite.com", "https://yoursite.com"]
    : ["http://localhost:3000"];
 
export function middleware(request: Request) {
  const origin = request.headers.get("origin");
  if (origin && !allowedOrigins.includes(origin)) {
    return new NextResponse(null, {
      status: 400,
      statusText: "Bad Request",
      headers: {
        "Content-Type": "text/plain",
      },
    });
  }
}
 
export default withAuth(
  function middleware(request: NextRequestWithAuth) {
    console.log(request.nextUrl.pathname);
    console.log(request.nextauth.token);
 
    // if (request.nextUrl.pathname.endsWith("/signin")) {
    //   console.log("Fired!");
    //   return NextResponse.redirect("/");
    // }
  },
  {
    callbacks: {
      authorized: ({ token }) => !!token,
    },
  }
);
 
export const config = { matcher: ["/profile", "/api/:path*"] };```
brisk pythonBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

teal igloo
#

try formatting your code so it's readable to people who want to help

#

look at code blocks (three backticks)

pine bane
#

My bad I’m on iOS

#

Did that fix it

teal igloo
#

three back ticks at the beginning and end

`

pine bane
#

That’s what I did hmmm

#

Alrighty fixed

pine bane