Openmaize v0.11.0 Openmaize.Login

Plug to handle login.

There are three options:

  • redirects - if true, which is the default, redirect on login
  • storage - storage method for the token
  • the default is :cookie
  • if storage is set to nil, redirects is automatically set to false
  • token_validity - length of validity of token (in minutes)
  • the default is 1440 minutes (one day)

Examples with Phoenix

In the web/router.ex file, add the following line (you can use a different controller and route):

post "/login", PageController, :login_user

And then in the page_controller.ex file, add:

plug Openmaize.Login when action in [:login_user]

If you want to use sessionStorage to store the token (this will also set redirects to false):

plug Openmaize.Login, [storage: nil] when action in [:login_user]

If you want to store the token in sessionStorage and have the token valid for just two hours:

plug Openmaize.Login, [storage: nil, token_validity: 120] when action in [:login_user]

Summary

Functions

Handle the login POST request

Callback implementation for c:Plug.init/1

Functions

call(conn, opts)

Handle the login POST request.

If the login is successful, a JSON Web Token will be returned.

init(opts)

Callback implementation for c:Plug.init/1.