Reference Source
import Session from 'flarum/Session.js'
public class | source

Session

The Session class defines the current user session. It stores a reference to the current authenticated user, and provides methods to log in/out.

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

The token that was used for authentication.

public

user: User | null

The current authenticated user.

Method Summary

Public Methods
public

authorize(xhr: XMLHttpRequest)

Apply an authorization header with the current token to the given XMLHttpRequest object.

public

login(identification: String, password: String, options: Object): Promise

Attempt to log in a user.

public

logout()

Log the user out.

Public Constructors

public constructor() source

Public Members

public token: String | null source

The token that was used for authentication.

public user: User | null source

The current authenticated user.

Public Methods

public authorize(xhr: XMLHttpRequest) source

Apply an authorization header with the current token to the given XMLHttpRequest object.

Params:

NameTypeAttributeDescription
xhr XMLHttpRequest

public login(identification: String, password: String, options: Object): Promise source

Attempt to log in a user.

Params:

NameTypeAttributeDescription
identification String

The username/email.

password String
options Object
  • optional

Return:

Promise

public logout() source

Log the user out.