Redirects not working as expected with Next.js

Hey there!

I’m wondering if anyones run into similar issues. I’m trying to implement gated routes by simply using redirects and user roles.

When I look at the docs, the example they give doesn’t seem to be valid.

For instance, I’ve got a route called /posts that I’m trying to gate with a role of admin the redirects file looks like this:

/posts/* 200! Role=admin
/posts/* / 401!

The validator doesn’t seem to like this rule but this is what was mentioned in the docs. Anyone have any idea?

I should also mention that my project is using NextJS!

Hi there @tOazter, the validator is not always in sync with what’s live. I can tell you that it should work though. Is the site that you’re testing this on currently on a Business or Enterprise plan? i ask since role based access control requires Business or above.

edit: This response was meant for a different community post I had open in another tab! :see_no_evil: But my last one should still be relevant!

1 Like

Hey @futuregerald thanks for the reply and demo. I wasn’t sure if the issue was my rules or if it was the codebase itself. It’s good to get clarity on the validator not quite being quite in sync.

What ended up happening is that I didn’t realize that NextJS’s internal Link component actually does everything on the client. That was an oversight on my part because of my lack of knowledge on the technology.

Turns out not using their internal linking and using a simple anchor tag actually solves the redirect issue. I guess because the client was managing routing, the redirect rules were never actually being invoked. Man is my face red…

So all is good and working as expected! Thanks again for the reply!

Hi there,

Yup, this is a similar problem people using Gatsby or an SPA would have. Glad you solved the issue and thanks for the update!