Skip to content

Redirection Issues with resource routes being non standard #72

@barelyhuman

Description

@barelyhuman

Issue

The issue is probably with the router since it seems to be trying to send the user back to the show method which isn't registered in the resource and added in except.

So, with the code example attached below, the expected flow is like so
profile.index is rendered => User modifies data => profile.update is called with the new data => User is redirected to profile.index and the new data is visible.

With the current flow, the first part works as updated but it redirects back to profile/:id instead.

I do have turbolinks in the app.

If turbolinks in enabled on the form (default behaviour)

  • the update goes through but redirection fails as it redirects back to the PUT request on the /profile url

If turbolinks is disabled on this one form

  • the redirections fail altogether

If turbolinks is not a part of the bundle

  • the redirections and form submission fail as well

Package version

"@adonisjs/auth": "^8.2.3",
"@adonisjs/core": "^5.8.0",
"@adonisjs/lucid": "^18.3.0",
"@adonisjs/repl": "^3.1.0",
"@adonisjs/session": "^6.2.0",
"@adonisjs/shield": "^7.0.0",
"@adonisjs/view": "^6.1.0",

Node.js and npm version

node - v18.16.0
npm - 9.5.1

Sample Code (to reproduce the issue)

export default class ProfilesController { 
	public async index({ view, response, auth }: HttpContextContract) {
	    const userDetails = await User.find(auth.user!.id)
	    return view.render('profiles/index', {
	      user: userDetails.serialize(),
		})
	}

	  public async update({
	    request,
	    response,
	    session,
	    auth,
	  }: HttpContextContract) {
	    const user = await User.find(auth.user!.id)
	    // modify users
	    await user!.save()
	    session.flash('message', 'Updated Profile')
	    return response.redirect().toRoute('ProfilesController.index')
	  }
 }

BONUS (a sample repo to reproduce the issue)

https://github.com/barelyhuman/resource-redir-adonis-issue

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions