mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-22 19:44: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,
|
"private": false,
|
||||||
"name": "bluelib",
|
"name": "bluelib",
|
||||||
"version": "0.12.5",
|
"version": "0.12.6",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"source": "src/index.js",
|
"source": "src/index.js",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import { royalnetApiRequest } from '../utils/royalnetApiRequest';
|
import { royalnetApiRequest } from '../utils/royalnetApiRequest';
|
||||||
import { route } from 'preact-router';
|
|
||||||
|
|
||||||
export default function(defaultInstanceUrl) {
|
export default function(defaultInstanceUrl) {
|
||||||
const [instanceUrl, setInstanceUrl] = useState(defaultInstanceUrl);
|
const [instanceUrl, setInstanceUrl] = useState(defaultInstanceUrl);
|
||||||
|
@ -35,20 +34,23 @@ export default function(defaultInstanceUrl) {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function storeValues(newInstanceUrl, newLoginStatus) {
|
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);
|
setInstanceUrl(newInstanceUrl);
|
||||||
setLoginStatus(newLoginStatus);
|
setLoginStatus(newLoginStatus);
|
||||||
console.debug("Saving login data in the localStorage...");
|
console.debug("Saving login data in the localStorage...");
|
||||||
window.localStorage.setItem("instanceUrl", newInstanceUrl);
|
window.localStorage.setItem("instanceUrl", newInstanceUrl);
|
||||||
window.localStorage.setItem("loginStatus", JSON.stringify(newLoginStatus));
|
window.localStorage.setItem("loginStatus", JSON.stringify(newLoginStatus));
|
||||||
route("/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
console.debug("User requested logout, clearing loginStatus and localStorage...");
|
console.debug("User requested logout, clearing loginStatus and localStorage...");
|
||||||
setLoginStatus(null);
|
setLoginStatus(null);
|
||||||
window.localStorage.setItem("loginStatus", null);
|
window.localStorage.setItem("loginStatus", null);
|
||||||
route("/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [instanceUrl, loginStatus, storeValues, logout]
|
return [instanceUrl, loginStatus, storeValues, logout]
|
||||||
|
|
Loading…
Reference in a new issue