MCPcopy Create free account
hub / github.com/pollinations/pollinations / updateAuthUI

Function updateAuthUI

apps/catgpt/script.js:485–558  ·  view source on GitHub ↗
({ skipModelPick = false } = {})

Source from the content-addressed store, hash-verified

483}
484
485async function updateAuthUI({ skipModelPick = false } = {}) {
486 const loggedOutEl = $("authLoggedOut");
487 const loggedInEl = $("authLoggedIn");
488 if (!loggedOutEl || !loggedInEl) return;
489
490 $("authLoginBtn").onclick = () => {
491 window.location.href = getAuthorizeUrl();
492 };
493 $("authLogoutBtn").onclick = () => {
494 clearApiKey();
495 updateAuthUI();
496 notify("Logged out. Log in to use CatGPT.");
497 };
498
499 const generatorSection = document.querySelector(".generator-section");
500 const heroHeader = document.querySelector("header");
501
502 const apiKey = getStoredApiKey();
503 if (!apiKey) {
504 show(loggedOutEl);
505 hide(loggedInEl);
506 hide(generatorSection);
507 show(heroHeader);
508 return;
509 }
510
511 hide(loggedOutEl);
512 show(loggedInEl);
513 show(generatorSection);
514 hide(heroHeader);
515 $("authApiKey").textContent = `${apiKey.substring(0, 4)}••••••••`;
516
517 // Pick best available model (skip if URL param already set one)
518 if (!skipModelPick) {
519 pickModel(apiKey).then(({ model, isPremium }) => {
520 setActiveModel(model);
521 const upsellEl = $("modelUpsell");
522 isPremium ? hide(upsellEl) : show(upsellEl);
523 });
524 }
525
526 try {
527 const [profile, balance] = await Promise.all([
528 fetchProfile(apiKey).catch(() => null),
529 fetchBalance(apiKey).catch(() => null),
530 ]);
531
532 if (profile) {
533 const name = profile.githubUsername || "User";
534 $("authUserName").textContent = name;
535
536 const avatarImg = $("authAvatar");
537 const avatarFallback = $("authAvatarFallback");
538 if (profile.image) {
539 avatarImg.src = profile.image;
540 show(avatarImg);
541 hide(avatarFallback);
542 } else {

Callers 1

script.jsFile · 0.85

Calls 11

getAuthorizeUrlFunction · 0.90
clearApiKeyFunction · 0.90
getStoredApiKeyFunction · 0.90
pickModelFunction · 0.90
fetchProfileFunction · 0.90
fetchBalanceFunction · 0.90
$Function · 0.85
notifyFunction · 0.85
setActiveModelFunction · 0.85
showFunction · 0.70
hideFunction · 0.70

Tested by

no test coverage detected