getx icon indicating copy to clipboard operation
getx copied to clipboard

return null in GetMiddleware not work as expect

Open wliu6v opened this issue 3 years ago • 13 comments

Describe the bug

README says return null in GetMiddleware.redirectDelegate will makes no redirect. (see https://github.com/jonataslaw/getx#redirect ) With this feature, we can avoid entering the login page while we are already logged in. But I found it doesn't work.

**Reproduction code

Here's a example, I forked example_nav2 and just changed this line. https://github.com/wliu6v/getx/blob/master/example_nav2/lib/app/modules/root/views/drawer.dart#L55

image

Expected behavior & To Reproduce

As expected, with the EnsureNotAuthedMiddleware in place, clicking the Login item in the slidermenu should not enter the login page. But in fact, it does, and generates the following log

[GETX] Redirect to null
[GETX] "DashboardController" onDelete() called

Screenshots

Here's a screen record. The first login is OK, but the second login shouldn't exist.

https://user-images.githubusercontent.com/5987831/157031540-e4db5e91-fb70-476d-97ff-bfc8dc87a01e.mp4

Flutter Version:

Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm

Getx Version: In my test, I forked the whole Getx project, use master branch to test it. So the version should be 5.0.0-beta.30

In my own project, I use 4.6.1.

Describe on which device you found the bug:

OnePlus 8 , Android version 10.

wliu6v avatar Mar 07 '22 12:03 wliu6v

I can fixed it by add these lines in get_route_delegate : do nothing for _activePages when middleware return null.

I haven't fully tested this, so I won't create a pull request. But if anyone else wants to prevent enter new page by returning null in the middleware, they can try this immature solution.

image

wliu6v avatar Mar 08 '22 02:03 wliu6v

interesting. What happens if you return the same parameter received rather null, using the master version?

jonataslaw avatar Mar 08 '22 11:03 jonataslaw

@jonataslaw seems nothing different between return null and return route in auth_middleware.dart -> EnsureNotAuthedMiddleware.

wliu6v avatar Mar 08 '22 12:03 wliu6v

I get the similar problem, i can't get arguments passed from a page to another when i put the middleware. I see
[GETX] Redirect to null everytime and i believe it is the problem. I'm looking for the solution.

progrems avatar May 22 '22 23:05 progrems

Same question

wxuonline avatar May 24 '22 03:05 wxuonline

same here

TaoufikElkahlaoui avatar Nov 06 '22 14:11 TaoufikElkahlaoui

Same.

lxbworld avatar Nov 16 '22 00:11 lxbworld

same

ajayld avatar Mar 01 '23 11:03 ajayld

any updates?

galiperkin avatar May 25 '23 10:05 galiperkin

same

wildsurfer avatar Jun 17 '23 17:06 wildsurfer

same

RaphaelRat avatar Jul 04 '23 21:07 RaphaelRat

@jonataslaw any news?

galiperkin avatar Jul 07 '23 07:07 galiperkin

截屏2024-04-30 10 13 21 if the runMiddleware function returns null, this code will be the original value. So it makes no difference whether you call super.redirectDelegate(route) or return null

Echo-BraveShine avatar Apr 30 '24 02:04 Echo-BraveShine