I would like add "guards" to certain urls. These urls should only be accessed when the user is logged in. If not logged in i want to redirect the user to the login page. After a successful login i want the user to be "redirected" to the original hash.
This is my router
@dom
def outlet: Binding[Node] = {
<div>{
route.state.bind match {
case s: View if UserService.hasRole("admin") => s.render.bind
case s if !UserService.isLoggedIn() => loginPage.render(Some(s.hash)).bind
case _ => <div>Unknown</div>
}
}</div>
The loginPage then changes the window hash after a successful login:
def login(username: String, password:String, orginalHash: Option[String]) =
UserService.login(username,password).andThen{
case Success(v) =>
println(s"changing hash to $orginalHash")
orginalHash.map(_.substring(1)).foreach(window.location.hash=_)
case Failure(e) => message.value = "Wrong username/password"
}
However i guess because the hash in fact does not change, it does not update the page:
- Say i go to
/index.html/#/foobar - The "guard" kicks in and the login page is shown (url remains
/index.html/#/foobar) - Value of the
orginalHashis#/foobar - changing the
location.hashto/foobardoes nothing
Is there a way to manipulate the router. Is there perhaps an api to change the current page?