Next.js Discord

Discord Forum

Tailwind not applied on middleware redirects

Answered
American Sable posted this in #help-forum
Open in Discord
American SableOP
Quite a basic example here. Using the with-supabase example: https://supabase.com/docs/guides/auth/auth-helpers/nextjs#automatic-configuration-recommended

Tailwind on /login is applied correctly if you use this example as is, or navigate to that page directly.

However, in the middleware, if you add some logic to redirect the user, then tailwind is no longer applied to the styling of /login

middleware.ts
  if (!user && req.nextUrl.pathname !== '/login') {
    return NextResponse.redirect(new URL('/login', req.url))
  }


If I check browser logs, with this middleware codeblock inserted, I can see
main-app.js?v=1692001396459:1 Uncaught SyntaxError: Unexpected token '<' (at main-app.js?v=1692001396459:1:1)
webpack.js?v=1692001396459:1 Uncaught SyntaxError: Unexpected token '<' (at webpack.js?v=1692001396459:1:1)


however if i remove it, there are no browser errors and tailwind loads

Any idea why this might be?
Answered by joulev
You have to use a matcher to exclude static paths
View full answer

6 Replies