如何使用sails-permissions登录后重定向帆

5 node.js sails.js sails-permissions

我刚刚开始使用sails并且正在尝试实现身份验证.我按照建议安装了所有内容,然后用jade创建了一个简单的登录表单:

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

这会记录authentication successful并转发给我返回页面

{
  "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"
}
Run Code Online (Sandbox Code Playgroud)

现在我想将新登录的用户重定向到任何页面,所以我尝试将表单的操作更改为

/auth/local/login
Run Code Online (Sandbox Code Playgroud)

它重定向到/ login,但是记录

warn: Error: Invalid action
Run Code Online (Sandbox Code Playgroud)

服务器端.

在我的config/routes文件中,我有一个这样的路由:

"/login" : {
    view:"login"
}
Run Code Online (Sandbox Code Playgroud)

登录后在帆中设置重定向的正确方法是什么?

has*_*sin 3

通过/auth/local/login,它试图呼吁login采取行动实施护照本地战略。但正如您从源代码中看到的,本地策略有三个操作:

register:此方法根据指定的电子邮件、用户名和密码创建新用户,并为新创建的用户分配本地 Passport。

connect:此功能可用于为还没有本地 Passport 的用户分配本地 Passport。如果用户使用第三方服务注册并且从未设置密码,就会出现这种情况。

disconnect:断开护照与用户的连接

对于其他操作,它会抛出Invalid action错误。

成功登录后重定向的正确方法是使用next查询参数

/auth/local?next=login
Run Code Online (Sandbox Code Playgroud)