How to redirect sails after logging in with sails permissions

I just started using sails and am trying to implement authentication. I installed everything as advised, and then created a simple login form with jade:

form(action="/auth/local", method="post") div input(name="identifier" type="text") div input(name="password" type="password") div input(type="submit") 

This authentication successful log also sends me to the page, returning

 { "createdBy": 1, "owner": 1, "username": "admin", "email": " admin@example.com ", "id": 1, "createdAt": "2015-09-25T18:14:20.000Z", "updatedAt": "2015-09-25T18:39:30.000Z", "gravatarUrl": "https://gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61" } 

Now I want to redirect the newly registered user to any page, so I tried to change the action of the form to

 /auth/local/login 

which redirects / login but registers

 warn: Error: Invalid action 

server side.

In my config / routes file, I have a route like this:

 "/login" : { view:"login" } 

What is the correct way to set up redirection in sails after logging in?

+6
source share
1 answer

Using /auth/local/login he tries to invoke the login action for the local passport strategy. But, as you can see from source , there are three actions in the local strategy:

register : this method creates a new user from the specified username, username and password and assigns a local passport to the newly created user.

connect : this function can be used to assign a local passport to a user who no longer has it. This will happen if the user is registered using a third-party service and therefore never sets a password.

disconnect : Disconnect the passport from the user

For other actions, this will throw an Invalid action error.

The correct way to redirect after a successful login is to use the next query parameter :

 /auth/local?next=login 
+4
source

All Articles