auth: use unicode b64 encoding on browser

brought over unicodeB64Encode/Decode from my other filaments project.
Fixes #364.
pull/366/head
Harvey Tindall 3 months ago
parent 02f4ba6e8e
commit 6347495b5b
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -291,3 +291,16 @@ export function bindManualDropdowns() {
};
}
}
export function unicodeB64Decode(s: string): string {
const decoded = atob(s);
const byteArray = Uint8Array.from(decoded, (m) => m.codePointAt(0));
const toUnicode = new TextDecoder().decode(byteArray);
return toUnicode;
}
export function unicodeB64Encode(s: string): string {
const encoded = new TextEncoder().encode(s);
const bin = String.fromCodePoint(...encoded);
return btoa(bin);
}

@ -1,5 +1,5 @@
import { Modal } from "../modules/modal.js";
import { toggleLoader, _post } from "../modules/common.js";
import { toggleLoader, _post, unicodeB64Encode } from "../modules/common.js";
export class Login {
loggedIn: boolean = false;
@ -68,7 +68,7 @@ export class Login {
const refresh = (username == "" && password == "");
req.open("GET", this._url + (refresh ? "token/refresh" : "token/login"), true);
if (!refresh) {
req.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
req.setRequestHeader("Authorization", "Basic " + unicodeB64Encode(username + ":" + password));
}
req.onreadystatechange = ((req: XMLHttpRequest, _: Event): any => {
if (req.readyState == 4) {

Loading…
Cancel
Save