Auth

Perform 3Box authentication operations

Auth API methods allow developers to request interactive access to a user's 3Box profile and spaces. Authentication is required to perform stateful operations on 3Box such as updating data, decrypting private data, and generally interacting with the user's data stores in a meaningful way.

Onboarding (SSO): The Auth API, combined with the Profiles API and Storage API, enable frictionless user onboarding and SSO using 3Box. Developers can authenticate a user and then read existing data from their profile and spaces to streamline the onboarding process.

Static

Stateful

Static

Box.openBox(address, ethereumProvider, opts)

Authenticates the 3Box associated with the given address.

Kind: static method of Box Returns: Box - the 3Box instance for the given address

Param

Type

Description

address

String

An ethereum address

ethereumProvider

ethereumProvider

An ethereum provider

opts

Object

Optional parameters

opts.consentCallback

function

A function that will be called when the user has consented to opening the box

opts.pinningNode

String

A string with an ipfs multi-address to a 3box pinning node

opts.ipfs

Object

A js-ipfs ipfs object

opts.addressServer

String

URL of the Address Server

Example:

const box = await Box.openBox(0x234..., window.ethereum)

Box.isLoggedIn(address)

Check if the address is currently authenticated.

Kind: static method of Box Returns: Boolean - Returns true if the user is logged in.

Param

Type

Description

address

String

An ethereum address

Stateful

box.openSpace(name, opts)

Authenticates a space in the user's 3Box.

Kind: instance method of Box Returns: Space - the Space instance for the given space name

Param

Type

Description

name

String

The name of the space

opts

Object

Optional parameters

opts.consentCallback

function

A function that will be called when the user has consented to opening the space

opts.onSyncDone

function

A function that will be called when the space has finished syncing with the pinning node

Example:

const space = await box.openSpace("my-dapp")

box.onSyncDone(syncDone)

Sets the callback function that will be called once the users 3Box DB is fully synced with the latest updates.

Kind: instance method of Box

Param

Type

Description

syncDone

function

The function that will be called

box.logout()

Closes the 3box instance and clears local cache. If you call this, users will need to re-authenticate by signing a consent message the next time you call openBox.

Kind: instance method of Box