LightningWeb.UserAuth (Lightning v2.14.5-pre1)

View Source

The UserAuth controller.

Summary

Functions

Authenticates the user by looking into the session and remember me token.

Logs the user in by creating a new session token.

Logs the user out.

Assigns the token to a new session.

Used for LiveView routes that require the user to be reauthenticated.

Reauthenticate the user by using the sudo token

Used for routes that require the user to not be authenticated.

Returns to or redirects to the dashboard and potentially set remember_me token.

Used for API routes that require the resource to be authenticated. A resource can be a User or a ProjectRepoConnection

Used for routes that require the user to be authenticated.

Used for routes that require the user to be reauthenticated.

Require that the user has the superuser role

Functions

authenticate_bearer(conn, opts)

fetch_current_user(conn, opts)

Authenticates the user by looking into the session and remember me token.

get_bearer(conn)

log_in_user(conn, user)

Logs the user in by creating a new session token.

log_out_user(conn)

Logs the user out.

It clears all session data for safety. See renew_session.

mark_totp_pending(conn)

new_session(conn, token)

Assigns the token to a new session.

It renews the session ID and clears the whole session to avoid fixation attacks. See the renew_session function to customize this behaviour.

It also sets a :live_socket_id key in the session, so LiveView sessions are identified and automatically disconnected on log out. The line can be safely removed if you are not using LiveView.

on_mount(atom, params, session, socket)

Used for LiveView routes that require the user to be reauthenticated.

reauth_sudo_mode(conn, opts)

Reauthenticate the user by using the sudo token

redirect_if_user_is_authenticated(conn, opts)

Used for routes that require the user to not be authenticated.

redirect_with_return_to(conn, params \\ %{})

Returns to or redirects to the dashboard and potentially set remember_me token.

require_authenticated_api_resource(conn, opts)

Used for API routes that require the resource to be authenticated. A resource can be a User or a ProjectRepoConnection

require_authenticated_user(conn, opts)

Used for routes that require the user to be authenticated.

If you want to enforce the user email is confirmed before they use the application at all, here would be a good place.

require_sudo_user(conn, opts)

Used for routes that require the user to be reauthenticated.

require_superuser(conn, opts)

Require that the user has the superuser role

totp_pending?(conn)

totp_validated(conn)