Next.js Discord

Discord Forum

SEO while redirecting

Unanswered
Mugger Crocodile posted this in #help-forum
Open in Discord
Mugger CrocodileOP
So basically I have in my layout this piece of code to redirect those unlogged / unsubscribed:
const user = await auth();
  if (!user?.user.subscribed) {
      return redirect("/#pricing");
    }
  if (!user) {
    return redirect("/");
  }
, but I now have the problem that crawlers can't get my metadata from those pages. I tried using middleware, but there are still problems with checking if the user's subscribed.

9 Replies

@Mugger Crocodile like if (!isBot){ redirect }?
Yes, you can check for user agent
@Anay-208 | Ping in replies Yes, you can check for user agent
Mugger CrocodileOP
but can I use this outside of middleware?
Yes, you can get headers and check for User-Agent
but note, anyone can modify User-Agent
@Mugger Crocodile resolved?
@Mugger Crocodile ?