mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-03 03:12:31 +00:00
Refactor AuthService login logic
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]>
This commit is contained in:
1 parent
d3277be3ea
commit
f148653c39
3 files changed
+283
-156
No files matched your search
@@ -0,0 +1,53 @@
|
||||
|
||||
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";
|
||||
}
|
||||
Reference in new issue
Block a user