mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-07-23 02:58:50 +02:00
Login page of "subscribe dialog", still WIP, but looking nice
This commit is contained in:
parent
1599793de2
commit
6d343c0f1a
8 changed files with 366 additions and 11 deletions
web/src/app
|
@ -23,7 +23,10 @@ class Api {
|
|||
async auth(baseUrl, topic, user) {
|
||||
const url = topicUrlAuth(baseUrl, topic);
|
||||
console.log(`[Api] Checking auth for ${url}`);
|
||||
const response = await fetch(url);
|
||||
const headers = this.maybeAddAuthorization({}, user);
|
||||
const response = await fetch(url, {
|
||||
headers: headers
|
||||
});
|
||||
if (response.status >= 200 && response.status <= 299) {
|
||||
return true;
|
||||
} else if (!user && response.status === 404) {
|
||||
|
@ -33,6 +36,14 @@ class Api {
|
|||
}
|
||||
throw new Error(`Unexpected server response ${response.status}`);
|
||||
}
|
||||
|
||||
maybeAddAuthorization(headers, user) {
|
||||
if (user) {
|
||||
const encoded = new Buffer(`${user.username}:${user.password}`).toString('base64');
|
||||
headers['Authorization'] = `Basic ${encoded}`;
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
const api = new Api();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue