Files
Starlight_Lancher/apps/app-frontend/src/helpers/auth.js
Disy 5d181ed8cc
Some checks failed
Axolotl desktop CI / guardrails (push) Has been cancelled
Axolotl desktop CI / desktop (macos-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (ubuntu-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (windows-latest) (push) Has been cancelled
Axolotl desktop CI / website (push) Has been cancelled
Repository checks / typos (push) Has been cancelled
Repository checks / tombi (push) Has been cancelled
Rust checks / shear (push) Has been cancelled
Sync source to CNB / Sync Git ref (push) Has been cancelled
feat: refine StarLight skin integration
2026-09-14 11:29:48 +08:00

124 lines
3.8 KiB
JavaScript

/**
* All theseus API calls return serialized values (both return values and errors);
* So, for example, addDefaultInstance creates a blank instance object, where the Rust struct is serialized,
* and deserialized into a usable JS object.
*/
import { invoke } from '@tauri-apps/api/core'
// Example function:
// User goes to auth_url to complete flow, and when completed, authenticate_await_completion() returns the credentials
// export async function authenticate() {
// const auth_url = await authenticate_begin_flow()
// console.log(auth_url)
// await authenticate_await_completion()
// }
/**
* Check if the StarLight authentication server is reachable, throwing an
* exception if it is not reachable.
*/
export async function check_reachable() {
await invoke('plugin:auth|check_reachable')
}
/**
* Check the Mojang services mirrored by the Fallen proxy, returning their
* individual reachability states.
*/
export async function check_mojang_services() {
return await invoke('plugin:auth|check_mojang_services')
}
/**
* Authenticate a user with Hydra - part 1.
* This begins the authentication flow quasi-synchronously.
*
* @returns {Promise<DeviceLoginSuccess>} A DeviceLoginSuccess object with two relevant fields:
* @property {string} verification_uri - The URL to go to complete the flow.
* @property {string} user_code - The code to enter on the verification_uri page.
*/
export async function login(troubleLinks) {
return await invoke('plugin:auth|login', { troubleLinks })
}
export async function browser_login() {
return await invoke('plugin:auth|browser_login')
}
export async function begin_device_login() {
return await invoke('plugin:auth|begin_device_login')
}
export async function poll_device_login(deviceCode) {
return await invoke('plugin:auth|poll_device_login', { deviceCode })
}
export async function begin_yggdrasil_login(apiRoot, login, password) {
return await invoke('plugin:auth|begin_yggdrasil_login', { apiRoot, login, password })
}
export async function finish_yggdrasil_login(flowId, profileId) {
return await invoke('plugin:auth|finish_yggdrasil_login', { flowId, profileId })
}
export async function list_yggdrasil_saved_logins() {
return await invoke('plugin:auth|list_yggdrasil_saved_logins')
}
export async function get_yggdrasil_password(apiRoot, login) {
return await invoke('plugin:auth|get_yggdrasil_password', { apiRoot, login })
}
export async function set_yggdrasil_password(apiRoot, login, password) {
return await invoke('plugin:auth|set_yggdrasil_password', { apiRoot, login, password })
}
export async function delete_yggdrasil_password(apiRoot, login) {
return await invoke('plugin:auth|delete_yggdrasil_password', { apiRoot, login })
}
/**
* Creates and selects a local Minecraft account.
* @param {string} username
* @param {string} [uuid] Custom UUID as 32 hexadecimal characters, with or without hyphens
* @returns {Promise<Credential>}
*/
export async function add_offline_user(username, uuid) {
return await invoke('plugin:auth|add_offline_user', {
username,
...(uuid ? { uuid } : {}),
})
}
/**
* Retrieves the default user
* @return {Promise<UUID | undefined>}
*/
export async function get_default_user(offlineMode = false) {
return await invoke('plugin:auth|get_default_user', { offlineMode })
}
/**
* Updates the default user
* @param {UUID} user
*/
export async function set_default_user(user) {
return await invoke('plugin:auth|set_default_user', { user })
}
/**
* Remove a user account from the database
* @param {UUID} user
*/
export async function remove_user(user) {
return await invoke('plugin:auth|remove_user', { user })
}
/**
* Returns a list of users
* @returns {Promise<Credential[]>}
*/
export async function users(offlineMode = false) {
return await invoke('plugin:auth|get_users', { offlineMode })
}