Authentication

Description

The authentication module is used to authenticate a user with a backend API. It signs a unique message via the injected web3 provider and ships that to the API which verifies the data and sets up a session for that user. Once authenticated, the user will be able to execute off-chain actions such as commenting on a bounty, updating their profile details, etc.

Actions

getCurrentUser()

Retrieve the info for a currently logged in user

login()

Initiate the login process via the user's web3 provider

logout()

Remove any session data for a logged in user and log them out

resetLoginState()

Reset loading and error login state

resetLogoutState()

Reset loading and error logout state

State

The state is accessible via the selectors in the Authentication/selectors.js file. The full shape of the module's state is below.

{
  "user": UserObject,
  "nonce": Number,
	"signedUp":  Bool,
  "getCurrentUserState": {
    "loading": Bool,
    "loaded": Bool,
    "error": Bool
  },
  "loginState": {
    "loading": Bool,
    "error": Bool
  },
  "logoutState": {
    "loading": Bool,
    "error": Bool
  }
}

Selectors

loginStateSelector(state)

Retrieves the loginState object from the module state. The loading and error fields can be used to power UI elements while a user is logging in.

logoutStateSelector(state)

Retrieves the logoutState object from the module state. The loading and error fields can be used to power UI elements while a user is logging out.

getCurrentUserStateSelector(state)

Retrieves the getCurrentUserState object from the module state. The loading, loaded, and error fields can be used to power UI elements while a user is logging out.

getCurrentUserSelector(state)

Retrieves the user object from the module state. It defaults to null if no user has been successfully logged in yet.

getUserAddressSelector(state)

If a user has logged in, the selector will return that user's Ethereum address; otherwise it will return null.

hasUserSignedUp(state)

While attempting to login, a value will be set if the user has signed up on the platform yet. This can be used to kick off an on-boarding flow.