Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
user authentication example
// authenticate a user with a email + password
trait Authenticable {
def email: String
def password: String
def auth: Option[User] = dbAuthenticate(email, password) // dbAuthenticate is an example method that handles the authentication using a secure DB
def ~ = auth
}
case class UserForm(email: String, password: String) extends Authenticatable
// a login attempt is typically a POST request (SSL) to an endpoint `/api/v1/user/login` with `email` + `password`
for {
(email, pass) <- dataStream
uf <- UserForm(email, pass)
user <- uf ~
} yield user // will yeield a user if authentication is a success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment