the-sett / auth-elm / Auth

Manages the state of the authentication process, and provides an API to request authentication operations.


type alias Config =
{ authApiRoot : String }

The configuration specifying the API root to authenticate against.


type alias Credentials =
{ username : String
, password : String 
}

Username and password based login credentials.


type Status
    = Failed
    | LoggedOut
    | LoggedIn ({ scopes : List String, subject : String })

Auth states of interest to the consumer.

login : Credentials -> Platform.Cmd.Cmd Msg

Requests that a login be performed.

refresh : Platform.Cmd.Cmd Msg

Requests that an attempt be made to refresh the auth token from the refresh token.

logout : Platform.Cmd.Cmd Msg

Requests that a logout (including notifying the server of the logout) be performed.

unauthed : Platform.Cmd.Cmd Msg

Requests that the auth state be cleared to the LoggedOut state. Usually in response to receiving a 401 or 403 error from a server.


type alias Model =
{ authApiRoot : String
, innerModel : Private 
}

The complete state of this auth module. The 'innerModel' is opaque and holds the private state. The 'state' provides the state as visible to the consumer of this module.


type Msg

Describes the events this controller responds to.

init : Config -> Model

The initial unauthed state.

update : Msg -> Model -> ( Model, Platform.Cmd.Cmd Msg, Maybe Status )

Updates the model from Auth commands.