addon.auth

Available in userscripts✔️
Available in popup scripts✔️
Required manifest permissionsNone

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

TypeString
NullableNo

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

TypeString
NullableYes

Value of the scratchcsrftoken cookie.

Methods

addon.auth.fetchIsLoggedIn

Return valuePromise<Boolean>

Fetches whether the user is logged in or not.

addon.auth.fetchUsername

Return valuePromise<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 valuePromise<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 valuePromise<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 22 April 2022 by RedGuy12 on commit 686f6b7. Improve this page.

Comments

Make sure to follow the code of conduct. You can see this comment section on GitHub Discussions, as well as editing and removing your comment.