Response.redirect('back') when "back" ain't accessible with get method



I have 3 controllers:
A post on B
B post on C

My route file:

Route.get('/', 'AController.index')'/B', 'BController.index')'/C', 'CController.index')

When I validate the request from B to C, I do this:

const validation = await validate(data, rules)
await validate(data, rules)

if (validation.fails()) {

    return response.redirect('back')

So when the validation fails it tries to come back to B though it tells me that the route is not found:
“Route not found /B”

I’m not sure how I should handle this.


You got a route not found error because the route was actually not found :smile:. With what you have, return response.redirect('back') will redirect back to /B (GET request) which is not available. You have to define the route, probably:

Route.get('/B', 'BController.index')

Note the bolded


Yeah I know it’s because the route is not defined but I cannot define it, B shouldn’t be accessible with GET request.
What I don’t get is how I should handle validation in that case.


I don’t get. Maybe I should ask what you are trying to achieve.


Well I just have a controller A where the user enters inputs, then it goes to a second controller B where the user enters more inputs, then it goes to the controller C where he gets the summary of the actions he just did.
Does that make sense?


You can save inputs from subsequent stages in session


I’m not sure what you mean, I save inputs in session but what do I need to change in my code?
Where do you want me to use the inputs stored in session?


In controller C I guess. Since that’s where you want to display the summary. You know to show a form, you need to make a GET request to a certain method in a controller right?


That doesn’t fix my issue of validating the inputs sent from B to C though.
Well this route'/B', 'BController.index') makes me able to show a form in the index method without having to define a get route.


Maybe I should allow the get request on it and just check if I have the input from A in the session/request and if not I can redirect on A.