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*"] };```
#middleware origin and auth bugged / not working
11 messages · Page 1 of 1 (latest)
🔎 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)
try formatting your code so it's readable to people who want to help
Discord
Want to inject some flavor into your everyday text chat? You're in luck! Discord uses Markdown, a simple plain text formatting system that'll help you make your sentences stand out. Here's how to d...
look at code blocks (three backticks)
three back ticks at the beginning and end
`
Any solution u got to my bug ?