addon.auth

Available in userscripts ✔️
Available in persistent scripts ✔️
Available in popup scripts ✔️
Required manifest permissions None

Description

Allows addons to get information about the current Scratch account session.

Examples

Reacting to auth info change

addon.auth.addEventListener("change", async function() {
  console.log(await addon.auth.fetchIsLoggedIn());
});

Properties

addon.auth.scratchLang

Type String
Nullable No

Language of the Scratch website.
This language option can be changed by the user in the footer of Scratch’s website.
This property changing does not fire a change event.

addon.auth.csrfToken

Type String
Nullable Yes

Value of the scratchcsrftoken cookie.

Methods

addon.auth.fetchIsLoggedIn

Return value Promise<Boolean>

Fetches whether the user is logged in or not.

addon.auth.fetchUsername

Return value Promise<String | null>

Fetches the username of the currently logged in user.
Will resolve to null if addon.auth.fetchIsLoggedIn() returns Promise<false>.

addon.auth.fetchUserId

Return value Promise<Number | null>

Fetches the user ID of the currently logged in user.
Will resolve to null if addon.auth.fetchIsLoggedIn() returns Promise<false>.

addon.auth.fetchXToken

Return value Promise<String | null>

Fetches the value of the X-Token header used in the Scratch REST API.
Will resolve to null if addon.auth.fetchIsLoggedIn() returns Promise<false>.

Events

change

Fires when the CSRF token, username, user ID or X-Token change.


Last updated at 27 July 2021 by WorldLanguages on commit ee8aba6. Improve this page.