mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
Extracted complex logic from `AuthService.login` into private helper methods (`_validateAndNormalizeLoginInputs`, `_checkAccessControl`, `_updateGlobalState`, `_updateSavedProfiles`, `_initiatePostLogin`) to improve readability and maintainability. Moved `SimpleEventEmitter` to `js/utils/simpleEventEmitter.js` and auth constants/normalization helpers to `js/services/authUtils.js` to reduce file size and coupling. Co-authored-by: PR0M3TH3AN <[email protected]>
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
|
|
export const FALLBACK_PROFILE = {
|
|
name: "Unknown",
|
|
picture: "assets/svg/default-profile.svg",
|
|
about: "",
|
|
website: "",
|
|
banner: "",
|
|
lud16: "",
|
|
lud06: "",
|
|
};
|
|
|
|
export const FAST_PROFILE_RELAY_LIMIT = 3;
|
|
export const FAST_PROFILE_TIMEOUT_MS = 2500;
|
|
export const BACKGROUND_PROFILE_TIMEOUT_MS = 6000;
|
|
|
|
export function normalizeProviderId(providerId) {
|
|
return typeof providerId === "string" && providerId.trim()
|
|
? providerId.trim()
|
|
: "nip07";
|
|
}
|
|
|
|
export function normalizeAuthType(authTypeCandidate, providerId, providerResult) {
|
|
const candidates = [];
|
|
|
|
if (typeof authTypeCandidate === "string") {
|
|
candidates.push(authTypeCandidate);
|
|
}
|
|
|
|
if (providerResult && typeof providerResult === "object") {
|
|
const resultAuthType = providerResult.authType;
|
|
if (typeof resultAuthType === "string") {
|
|
candidates.push(resultAuthType);
|
|
}
|
|
|
|
const resultProviderId = providerResult.providerId;
|
|
if (typeof resultProviderId === "string") {
|
|
candidates.push(resultProviderId);
|
|
}
|
|
}
|
|
|
|
if (typeof providerId === "string") {
|
|
candidates.push(providerId);
|
|
}
|
|
|
|
for (const candidate of candidates) {
|
|
const trimmed = candidate.trim();
|
|
if (trimmed) {
|
|
return trimmed;
|
|
}
|
|
}
|
|
|
|
return "nip07";
|
|
}
|