Skip to content

API Reference

Samuel Elgozi edited this page Mar 15, 2020 · 2 revisions

Functions

listen(cb)

Set up a function that will be called whenever the user state is changed.

signOut()

Sign out the currently signed in user. Removes all data stored in the localStorage that's associated with the user.

authorizedRequest(resource, init)

Uses native fetch, but adds authorization headers otherwise the API is exactly the same as native fetch.

signInWithCustomToken(token)

Signs in or signs up a user by exchanging a custom Auth token.

signInWithProvider(options)

Start auth flow of a federated Id provider. Will redirect the page to the federated login page.

handleSignInRedirect()

Handles all sign in flows that complete via redirects. Fails silently if no redirect was detected.

signUp([email], [password])

Signs up with email and password or anonymously when no arguments are passed. Automatically signs the user in on completion.

signIn(email, password)

Signs in a user with email and password.

sendOobCode(requestType, [email])Promise

Sends an out-of-band confirmation code for an account. Can be used to reset a password, to verify an email address and send a Sign-in email link. The email argument is not needed only when verifying an email(In that case it will be completely ignored, even if specified), otherwise it is required.

resetPassword(code)string

Sets a new password by using a reset code. Can also be used to very oobCode by not passing a password.

fetchProvidersForEmail(email)ProvidersForEmailResponse

Returns info about all providers associated with a specified email.

fetchProfile([tokenManager])

Gets the user data from the server, and updates the local caches.

updateProfile(newData)

Update user's profile.

deleteAccount()

Deletes the currently logged in account and logs out.

Typedefs

ProviderOptions : Object

Settings object for an IDP(Identity Provider).

ProvidersForEmailResponse : Object

Object response from a "fetchProvidersForEmail" request.

oauthFlowOptions : Object

Setting object for the "startOauthFlow" method.

listen(cb)

Set up a function that will be called whenever the user state is changed.

Kind: global function

Param Type Description
cb function The function to call when the event is triggered.

signOut()

Sign out the currently signed in user. Removes all data stored in the localStorage that's associated with the user.

Kind: global function

authorizedRequest(resource, init)

Uses native fetch, but adds authorization headers otherwise the API is exactly the same as native fetch.

Kind: global function

Param Type Description
resource Request | Object | string the resource to send the request to, or an options object.
init Object an options object.

signInWithCustomToken(token)

Signs in or signs up a user by exchanging a custom Auth token.

Kind: global function

Param Type Description
token string The custom token.

signInWithProvider(options)

Start auth flow of a federated Id provider. Will redirect the page to the federated login page.

Kind: global function

Param Type Description
options oauthFlowOptions | string An options object, or a string with the name of the provider.

handleSignInRedirect()

Handles all sign in flows that complete via redirects. Fails silently if no redirect was detected.

Kind: global function

signUp([email], [password])

Signs up with email and password or anonymously when no arguments are passed. Automatically signs the user in on completion.

Kind: global function

Param Type Description
[email] string The email for the user to create.
[password] string The password for the user to create.

signIn(email, password)

Signs in a user with email and password.

Kind: global function

Param Type
email string
password string

sendOobCode(requestType, [email]) ⇒ Promise

Sends an out-of-band confirmation code for an account. Can be used to reset a password, to verify an email address and send a Sign-in email link. The email argument is not needed only when verifying an email(In that case it will be completely ignored, even if specified), otherwise it is required.

Kind: global function

Param Type Description
requestType 'PASSWORD_RESET' | 'VERIFY_EMAIL' | 'EMAIL_SIGNIN' The type of out-of-band (OOB) code to send.
[email] string When the requestType is PASSWORD_RESET you need to provide an email address, else it will be ignored.

resetPassword(code) ⇒ string

Sets a new password by using a reset code. Can also be used to very oobCode by not passing a password.

Kind: global function Returns: string - The email of the account to which the code was issued.

Param Type
code string

fetchProvidersForEmail(email) ⇒ ProvidersForEmailResponse

Returns info about all providers associated with a specified email.

Kind: global function

Param Type Description
email string The user's email address.

fetchProfile([tokenManager])

Gets the user data from the server, and updates the local caches.

Kind: global function Throws:

  • Will throw if the user is not signed in.
Param Type Description
[tokenManager] Object Only when not logged in.

updateProfile(newData)

Update user's profile.

Kind: global function Throws:

  • Will throw if the user is not signed in.
Param Type Description
newData Object An object with the new data to overwrite.

deleteAccount()

Deletes the currently logged in account and logs out.

Kind: global function Throws:

  • Will throw if the user is not signed in.

ProviderOptions : Object

Settings object for an IDP(Identity Provider).

Kind: global typedef Properties

Name Type Description
options.name string The name of the provider in lowercase.
[options.scope] string The scopes for the IDP, this is optional and defaults to "openid email".

ProvidersForEmailResponse : Object

Object response from a "fetchProvidersForEmail" request.

Kind: global typedef Properties

Name Type Description
allProviders Array.<string> All providers the user has once used to do federated login
registered boolean All sign-in methods this user has used.
sessionId string Session ID which should be passed in the following verifyAssertion request
signinMethods Array.<string> All sign-in methods this user has used.

oauthFlowOptions : Object

Setting object for the "startOauthFlow" method.

Kind: global typedef Properties

Name Type Default Description
provider string Name of the provider to use.
[context] string A string that will be returned after the Oauth flow is finished, should be used to retain context.
[linkAccount] boolean false Whether to link this oauth account with the current account. defaults to false.