mirror of
https://github.com/Casvt/MIND.git
synced 2026-02-19 11:54:46 -05:00
Sustain login for one hour (#39)
This commit is contained in:
@@ -47,7 +47,7 @@ function logout() {
|
||||
'method': 'POST'
|
||||
})
|
||||
.then(response => {
|
||||
sessionStorage.removeItem('api_key');
|
||||
localStorage.removeItem('MIND_api_key');
|
||||
window.location.href = `${url_prefix}/`;
|
||||
});
|
||||
};
|
||||
@@ -55,7 +55,7 @@ function logout() {
|
||||
// code run on load
|
||||
|
||||
const url_prefix = document.getElementById('url_prefix').dataset.value;
|
||||
const api_key = sessionStorage.getItem('api_key');
|
||||
const api_key = localStorage.getItem('MIND_api_key');
|
||||
if (api_key === null) {
|
||||
window.location.href = `${url_prefix}/`;
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ function login(data=null) {
|
||||
return response.json();
|
||||
})
|
||||
.then(json => {
|
||||
sessionStorage.setItem('api_key', json.result.api_key);
|
||||
localStorage.setItem('MIND_api_key', json.result.api_key);
|
||||
window.location.href = `${url_prefix}/reminders`;
|
||||
})
|
||||
.catch(e => {
|
||||
@@ -92,10 +92,26 @@ function create() {
|
||||
});
|
||||
};
|
||||
|
||||
function checkLogin() {
|
||||
fetch(`${url_prefix}/api/auth/status?api_key=${localStorage.getItem('MIND_api_key')}`)
|
||||
.then(response => {
|
||||
if (!response.ok) return Promise.reject(response.status);
|
||||
window.location.href = '/reminders';
|
||||
})
|
||||
.catch(e => {
|
||||
if (e === 401)
|
||||
console.log('API key expired')
|
||||
else
|
||||
console.log(e);
|
||||
});
|
||||
};
|
||||
|
||||
// code run on load
|
||||
|
||||
const url_prefix = document.getElementById('url_prefix').dataset.value;
|
||||
|
||||
checkLogin();
|
||||
|
||||
document.getElementById('login-form').setAttribute('action', 'javascript:login();');
|
||||
document.getElementById('create-form').setAttribute('action', 'javascript:create();');
|
||||
document.querySelectorAll('.switch-button').forEach(e => e.addEventListener('click', e => toggleWindow()));
|
||||
|
||||
Reference in New Issue
Block a user