add redirect for authenticated users to home page in middleware

This commit is contained in:
Danel Kungla
2025-09-02 16:25:27 +03:00
parent 3230dd7608
commit 612673ddf9

View File

@@ -165,6 +165,20 @@ async function doctorMiddleware(request: NextRequest, response: NextResponse) {
*/
function getPatterns() {
return [
{
pattern: new URLPattern({ pathname: '/' }),
handler: async (req: NextRequest, res: NextResponse) => {
const {
data: { user },
} = await getUser(req, res);
if (user) {
return NextResponse.redirect(
new URL(pathsConfig.app.home, req.nextUrl.origin).href,
);
}
},
},
{
pattern: new URLPattern({ pathname: '/admin/*?' }),
handler: adminMiddleware,