parent
cd3508dcb6
commit
84ab757e11
@ -18,6 +18,7 @@ export default class Apiclient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getUrls() {
|
static async getUrls() {
|
||||||
|
console.log("APICALL")
|
||||||
return (
|
return (
|
||||||
await axios.get('https://kauft.es/api?showVisits=true', {
|
await axios.get('https://kauft.es/api?showVisits=true', {
|
||||||
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
||||||
|
@ -1,21 +1,10 @@
|
|||||||
<script>
|
<script>
|
||||||
import UserStore from '$lib/UserStore';
|
import UserStore from '$lib/UserStore';
|
||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
import * as localForage from 'localforage';
|
|
||||||
import Apiclient from './Apiclient';
|
import Apiclient from './Apiclient';
|
||||||
|
|
||||||
$: logged_in = false;
|
$: logged_in = false;
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
localForage.getItem('userdata', (err, value) => {
|
|
||||||
if (value) {
|
|
||||||
if (value.token) {
|
|
||||||
UserStore.login(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const unsubscribe = UserStore.subscribe((value) => {
|
const unsubscribe = UserStore.subscribe((value) => {
|
||||||
logged_in = value.isLoggedIn;
|
logged_in = value.isLoggedIn;
|
||||||
});
|
});
|
||||||
|
@ -47,6 +47,9 @@ const userStore = () => {
|
|||||||
return state;
|
return state;
|
||||||
});
|
});
|
||||||
location.replace("/");
|
location.replace("/");
|
||||||
|
},
|
||||||
|
getCurrent(){
|
||||||
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,8 +2,20 @@
|
|||||||
import '../app.postcss';
|
import '../app.postcss';
|
||||||
import Sidebar from '$lib/Sidebar.svelte';
|
import Sidebar from '$lib/Sidebar.svelte';
|
||||||
import UserStore from '$lib/UserStore';
|
import UserStore from '$lib/UserStore';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import * as localForage from 'localforage';
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
UserStore.init();
|
||||||
|
localForage.getItem('userdata', (err, value) => {
|
||||||
|
if (value) {
|
||||||
|
if (value.token) {
|
||||||
|
UserStore.login(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
UserStore.init();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div style="min-height: 640px;" class="bg-white dark:bg-gray-800">
|
<div style="min-height: 640px;" class="bg-white dark:bg-gray-800">
|
||||||
|
@ -1,10 +1,21 @@
|
|||||||
<script>
|
<script>
|
||||||
import Apiclient from '$lib/Apiclient';
|
import Apiclient from '$lib/Apiclient';
|
||||||
|
import UserStore from '$lib/UserStore';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
|
||||||
$: urls = [];
|
$: urls = [];
|
||||||
let urlQuery = Apiclient.getUrls().then((res) => {
|
let urlQuery;
|
||||||
urls = res;
|
|
||||||
|
const unsubscribe = UserStore.subscribe((value) => {
|
||||||
|
if (value.isLoggedIn) {
|
||||||
|
urlQuery = Apiclient.getUrls().then((res) => {
|
||||||
|
urls = res;
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onDestroy(unsubscribe);
|
||||||
|
|
||||||
function deleteUrl(shortcode) {
|
function deleteUrl(shortcode) {
|
||||||
Apiclient.deleteUrl(shortcode).then(() => {
|
Apiclient.deleteUrl(shortcode).then(() => {
|
||||||
urls = urls.filter((url) => url.shortcode != shortcode);
|
urls = urls.filter((url) => url.shortcode != shortcode);
|
||||||
|
@ -7,7 +7,6 @@ import Apiclient from '$lib/Apiclient';
|
|||||||
$: password = "";
|
$: password = "";
|
||||||
$: error = "";
|
$: error = "";
|
||||||
|
|
||||||
UserStore.init();
|
|
||||||
async function login() {
|
async function login() {
|
||||||
try {
|
try {
|
||||||
const login = await Apiclient.login(username, password);
|
const login = await Apiclient.login(username, password);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user