Home Manual Reference Source
import Accounts from '@pageproof/sdk/src/api/Accounts.js'
public class | source

Accounts

Extends:

API → Accounts

Method Summary

Public Methods
public

activate(activationCode: string): Promise

Attempts to activate the user's account. This only applies to accounts which haven't been activated yet.

public

Generates a new activation code for a newly created account.

public

login(email: string, password: string): Promise<Session>

Starts a new session with PageProof given an already existing user.

public

Invalidates the current session.

public

register(email: string, password: string): Promise<Session>

Creates a new PageProof account.

Inherited Summary

From class API
public

Public Methods

public activate(activationCode: string): Promise source

Attempts to activate the user's account. This only applies to accounts which haven't been activated yet.

You can request a new activation code by calling Accounts#generateActivationCode. There is currently no way to easily extract the user's activation code from an email - it does require manual HTML traversal.

An activation code is automatically sent to any new accounts.

Params:

NameTypeAttributeDescription
activationCode string

The user's activation code, sent to them via email

Return:

Promise

Example:

Activate a user's account by providing the activation code
try {
  await client.accounts.activate('N7HLA9');
} catch (err) {
  console.log('Invalid activation code!');
}

See:

public generateActivationCode(): Promise source

Generates a new activation code for a newly created account. The activation code is sent to the user's email address, and contains a link for them to click.

This method is automatically called when calling Accounts#register. The only reason you would want to call this method is if the user entered the activation code incorrectly - as activation codes invalidate if the attempt is incorrect. This feature is intended to prevent spam accounts.

If you're looking to automate the process, you will need to manually traverse the HTML.

Return:

Promise

public login(email: string, password: string): Promise<Session> source

Starts a new session with PageProof given an already existing user.

Too many attempts to this API will temporarily cause any any further requests to be immediately rejected by the server.

Params:

NameTypeAttributeDescription
email string

The user's email address

password string

The user's secure password

Return:

Promise<Session>

Example:

Logging in and saving the session using the "localStorage" API
const session = await client.accounts.login('user@example.com', '<password>');
const sessionJSON = JSON.stringify(session);
localStorage.setItem('session', sessionJSON);

public logout(): Promise source

Invalidates the current session.

Rejects if there is no current session, or if the session has already been invalidated.

Return:

Promise

public register(email: string, password: string): Promise<Session> source

Creates a new PageProof account.

This method does a few different things;

  • Hashes the user's password
  • Locally generates a 2048-bit RSA key pair
  • Encrypts the user's RSA private key with their unhashed password
  • Sends the encrypted private key, and the user's hashed password to PageProof
  • Sends the user an activation email with their activation code

The Session object contains the user's secure credentials. These credentials are never transmitted over HTTP. Only encrypted & hashed data is ever sent to PageProof. It's recommended that you serialise the Session object so you can re-authenticate using PageProof#setSession at a later stage. Doing this means you should be careful about where you store the serialised data, as the Session contains the user's unencrypted RSA private key.

Note: You can expect this method to take some time to resolve, as generating a RSA key pair is usually very time consuming.

Params:

NameTypeAttributeDescription
email string

The user's email address

password string

The user's password

Return:

Promise<Session>

Example:

Registering a new PageProof account, and serialising the Session
try {
  const session = await client.accounts.register('user@example.com', '<password>');
  const sessionJSON = JSON.stringify(session);
  localStorage.setItem('session', sessionJSON);
} catch (err) {
  // This most commonly occurs when the email address is already registered...
  console.log('Unable to create account:', err);
}