NextAuth Middleware config

Hey guys, first time I've used middleware, I just need a hand.
2 Replies
mac
macOP3y ago
import { withAuth } from "next-auth/middleware";

export default withAuth(
async function middleware(req) {
console.log(req.nextauth.token);
},
{
callbacks: {
authorized: ({ token }) => token?.authenticated === true,
},
}
);
export const config = { matcher: ["/dashboard/:path*"] };
import { withAuth } from "next-auth/middleware";

export default withAuth(
async function middleware(req) {
console.log(req.nextauth.token);
},
{
callbacks: {
authorized: ({ token }) => token?.authenticated === true,
},
}
);
export const config = { matcher: ["/dashboard/:path*"] };
This is my middleware.ts file, currently it checks that each user that accesses the dashboard is authenticated. What I want to add onto this is: - User cant access a guild that they are not in (I have a function which fetches the guilds of a user) - User cant access the admin panel ('/dashboard/${guild.id}/admin') if they are not the owner of the guild - User cant access a guild url that doesnt have the discord application within the guild ( I have a function which responses with a boolean by inputting a guild.id) I just have cant piece together how I can do this within the middleware.ts file
Patryk Makowski
Hey, have you solved it?
Want results from more Discord servers?
Add your server