netlify / netlify/cli

Role based redirects does not work as intended in dev mode

Open
#4,320 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: redirects type: bug
Dominant language
TypeScript
Stars
1.9k
Forks
474
Avg merge
23h 30m
Merged PRs (30d)
53

Description

Describe the bug

When you make a role based rewrite (not redirect) on dev mode or live dev mode the rewrite to the page returns 404.
Works correctly on production.
https://answers.netlify.com/t/role-based-redirects-does-not-work-as-intended-in-dev-mode/50667

To Reproduce

Steps to reproduce the behavior:

Make a configuration like the one you see below.

[[redirects]]
  from = "/*"
  to = "/pro/:splat"
  status = 200
  conditions = {Role = ["pro"]}

Put a test.html file in /pro .
Login as user with role set to "pro"
Try to access /pro/test.html at /test.html

Configuration

[build]
  publish = "dist"
  functions = "functions"
[dev]
  publish = "dist"
  functions = "functions"
[functions]
  node_bundler = "esbuild"
[[redirects]]
  from = "/pro/*"
  to = "/:splat"
  force = true
  status = 302
[[redirects]]
  from = "/free/*"
  to = "/:splat"
  force = true
  status = 302
[[redirects]]
  from = "/*"
  to = "/pro/:splat"
  status = 200
  conditions = {Role = ["pro"]}
[[redirects]]
  from = "/*"
  to = "/free/:splat"
  status = 200
System:
    OS: Linux 5.16 Fedora Linux 35 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 150.58 MB / 15.27 GB
    Container: Yes
    Shell: 5.1.8 - /bin/bash
  Binaries:
    Node: 16.6.2 - ~/.nvm/versions/node/v16.6.2/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v16.6.2/bin/yarn
    npm: 7.20.3 - ~/.nvm/versions/node/v16.6.2/bin/npm
  npmGlobalPackages:
    netlify-cli: 8.13.2

Expected behavior

The browser should open test.html

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the role-based rewrite with the supplied netlify.toml configuration in Netlify CLI dev mode, comparing it with production behavior. Trace the dev-mode redirect handling from the CLI entry point; done means /test.html serves test.html for a user with the pro role without returning 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.