mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-22 11:34:21 +00:00
0.12.6
This commit is contained in:
parent
cd54429034
commit
2a13b0fdf6
2 changed files with 7 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"private": false,
|
||||
"name": "bluelib",
|
||||
"version": "0.12.5",
|
||||
"version": "0.12.6",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"source": "src/index.js",
|
||||
"main": "dist/index.js",
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { useEffect, useState } from 'preact/hooks';
|
||||
import { royalnetApiRequest } from '../utils/royalnetApiRequest';
|
||||
import { route } from 'preact-router';
|
||||
|
||||
export default function(defaultInstanceUrl) {
|
||||
const [instanceUrl, setInstanceUrl] = useState(defaultInstanceUrl);
|
||||
|
@ -35,20 +34,23 @@ export default function(defaultInstanceUrl) {
|
|||
}, []);
|
||||
|
||||
function storeValues(newInstanceUrl, newLoginStatus) {
|
||||
console.debug(`Successfully logged in as ${newLoginStatus.user.username} @ ${newInstanceUrl} !`);
|
||||
if(newLoginStatus !== null) {
|
||||
console.debug(`Successfully logged in as ${newLoginStatus.user.username} @ ${newInstanceUrl} !`);
|
||||
}
|
||||
else {
|
||||
console.debug(`Changed instanceUrl to ${newInstanceUrl} !`);
|
||||
}
|
||||
setInstanceUrl(newInstanceUrl);
|
||||
setLoginStatus(newLoginStatus);
|
||||
console.debug("Saving login data in the localStorage...");
|
||||
window.localStorage.setItem("instanceUrl", newInstanceUrl);
|
||||
window.localStorage.setItem("loginStatus", JSON.stringify(newLoginStatus));
|
||||
route("/");
|
||||
}
|
||||
|
||||
function logout() {
|
||||
console.debug("User requested logout, clearing loginStatus and localStorage...");
|
||||
setLoginStatus(null);
|
||||
window.localStorage.setItem("loginStatus", null);
|
||||
route("/");
|
||||
}
|
||||
|
||||
return [instanceUrl, loginStatus, storeValues, logout]
|
||||
|
|
Loading…
Reference in a new issue