I've just started using sails and am trying to implement authentication. I installed everything like adviced, 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 logs authentication successful
and forwards me to the page, returning
{
"createdBy": 1,
"owner": 1,
"username": "admin",
"email": "[email protected]",
"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 logged in user to any page, so I tried to change the form's action to
/auth/local/login
which redirects to /login, but logs
warn: Error: Invalid action
serverside.
In my config/routes file I have a route like this:
"/login" : {
view:"login"
}
What is the correct way to setup redirection in sails after login?
With
/auth/local/login
, it tries to calllogin
action for passport local strategy. But as you can see from source local strategy have three actions:register
: This method creates a new user from a specified email, username and password and assign the newly created user a local Passport.connect
: This function can be used to assign a local Passport to a user who doens't have one already. This would be the case if the user registered using a third-party service and therefore never set a password.disconnect
: Disconnect a passport from a userFor other actions it'll throw
Invalid action
error.The right way to redirect after successful login is to use
next
query parameter: