azures04 d2ae3122c9 Add Discord OAuth2 login and refactor authentication
Implemented Discord OAuth2 authentication flow with a new Discord.cs handler and integrated it into Program.cs. Refactored authentication logic to use shared JsonSerializerOptions from LauncherConstants. Updated BashUtils with cross-platform URL opening, improved MojangAPI to use shared HttpClient, and enhanced frontend login and log handling in logged.js and login.js.
2026-01-24 23:35:02 +01:00

49 lines
1.3 KiB
JavaScript

const version = document.querySelector("#version")
const information = document.querySelector(".information")
document.addEventListener("DOMContentLoaded", async () => {
version.innerText = `Launcher ${await system.call("launcher::version")}`
})
function showInformation() {
return information.removeAttribute("hidden")
}
function hideInformation() {
return information.setAttribute("hidden", "")
}
async function login() {
const username = document.querySelector("#username").value
const password = document.querySelector("#password").value
const result = await system.call("auth::lentia", { username, password })
await processLoginResult(result)
}
function clearPassword() {
password.value = ""
}
async function requestLoginWithOAuth2() {
showFrame("oauth2")
hideInformation()
showLoadingBar()
const result = await system.call("oauth2::discord")
await processLoginResult(result, true)
}
async function processLoginResult(payload, showDefaultPage = false) {
if (payload.success == false) {
await system.call("dialog::error", {
title: payload.error.error,
message: payload.error.errorMessage
})
if (showDefaultPage) {
hideLoadingBar()
showFrame("provider")
}
}
}
hideLoadingBar()
showFrame("provider")