Scala-Lift redirect user after login

467 views Asked by At

I want to redirect to a certain page after a user logs in to my Scala Lift web application. I found this answer which doesn't seem to work:

In my User object (which is a MetaMegaProtoUser) I override the following method like so:

object User extends User with MetaMegaProtoUser[User] {
    override def loginFirst = If(
    loggedIn_? _,
    () => {
      import net.liftweb.http.{RedirectWithState, RedirectState}
      val uri = Full("/myPicks")
      println("login sucessful .. redirecting!..")
      RedirectWithState(
        loginPageURL,
        RedirectState( ()=>{loginRedirect.set(uri)})
      )
    }
  )


}

This doesn’t work. Any ideas?

1

There are 1 answers

1
jcern On BEST ANSWER

loginFirst defines a LocParam which can be used for specifying where to send the user if they are not logged in. It is used in conjunction with SiteMap.

For the page you want to protect, you can modify that entry like:

Menu("Protected Page") / "protected" >> User.loginFirst

That should test whether the user is logged in when you access /protected and, if they are not, set the loginRedirect SessionVar and display the login form. On a successful login, you should be redirected to the page specified in loginRedirect.

I believe you can also just use: override def homePage = "/myPicks" if you want to set a default page to redirect to.