Working signout button
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
(() => {
|
||||
const profileForm = document.querySelector('#profile-form');
|
||||
const passwordForm = document.querySelector('#password-form');
|
||||
const mastodonForm = document.querySelector('#mastodon-form');
|
||||
const profileLogoutButton = document.querySelector('#logout-button');
|
||||
const accessToken = localStorage.getItem('linklogAccessToken');
|
||||
@@ -90,6 +91,19 @@ mastodonForm.addEventListener('submit', async (event) => {
|
||||
setStatus('#mastodon-status', response.ok ? 'Mastodon settings saved.' : 'Could not save Mastodon settings.', !response.ok);
|
||||
});
|
||||
|
||||
passwordForm.addEventListener('submit', async (event) => {
|
||||
event.preventDefault();
|
||||
const response = await fetch('/api/user/password', {
|
||||
method: 'PUT',
|
||||
headers: authHeaders(true),
|
||||
body: JSON.stringify(Object.fromEntries(new FormData(passwordForm))),
|
||||
});
|
||||
const status = document.querySelector('#password-status');
|
||||
status.textContent = response.ok ? 'Password changed.' : 'Could not change password.';
|
||||
status.style.color = response.ok ? '#94e2d5' : '#f38ba8';
|
||||
if (response.ok) passwordForm.reset();
|
||||
});
|
||||
|
||||
Promise.all([loadProfile(), loadMastodonConfig()]).catch((error) => {
|
||||
setStatus('#profile-status', accessToken ? error.message : 'Please sign in first.', true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user