Compare commits
5 Commits
4f5b7f38fb
...
2010cc3260
Author | SHA1 | Date | |
---|---|---|---|
2010cc3260 | |||
8c1a2d319b | |||
b57aa535de | |||
84ab757e11 | |||
cd3508dcb6 |
@ -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}` }
|
||||||
@ -62,7 +63,9 @@ export default class Apiclient {
|
|||||||
static async logout() {
|
static async logout() {
|
||||||
return (
|
return (
|
||||||
await axios.post(`https://kauft.es/api/auth/logout`, {}, {
|
await axios.post(`https://kauft.es/api/auth/logout`, {}, {
|
||||||
headers: { Authorization: `Bearer ${UserStore.state.token}` }
|
headers: { Authorization: `Bearer ${UserStore.state.token}`,
|
||||||
|
validateStatus: null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
).data;
|
).data;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
});
|
});
|
||||||
@ -23,7 +12,7 @@
|
|||||||
onDestroy(unsubscribe);
|
onDestroy(unsubscribe);
|
||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
await Apiclient.logout().catch((e)=>{});
|
await Apiclient.logout().catch((e) => {});
|
||||||
UserStore.logout();
|
UserStore.logout();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -166,13 +155,15 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
{#if logged_in}
|
||||||
<div class="flex items-center px-4 -mx-2">
|
<div class="flex items-center px-4 -mx-2">
|
||||||
<img
|
<img
|
||||||
class="object-cover mx-2 rounded-full h-9 w-9"
|
class="object-cover mx-2 rounded-full h-9 w-9"
|
||||||
src="https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80"
|
src="https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80"
|
||||||
alt="avatar"
|
alt="avatar"
|
||||||
/>
|
/>
|
||||||
<h4 class="mx-2 font-medium text-gray-800 dark:text-gray-200 hover:underline">John Doe</h4>
|
<h4 class="mx-2 font-medium text-gray-800 dark:text-gray-200 hover:underline">Username here</h4>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -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();
|
UserStore.init();
|
||||||
|
localForage.getItem('userdata', (err, value) => {
|
||||||
|
if (value) {
|
||||||
|
if (value.token) {
|
||||||
|
UserStore.login(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
</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,8 +1,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import Apiclient from '$lib/Apiclient';
|
import Apiclient from '$lib/Apiclient';
|
||||||
|
import UserStore from '$lib/UserStore';
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
|
||||||
let shortcode = $page.query.get('shortcode');
|
let shortcode = $page.query.get('shortcode');
|
||||||
|
|
||||||
$: urlDetails = {
|
$: urlDetails = {
|
||||||
shortcode: 'Loading...',
|
shortcode: 'Loading...',
|
||||||
url: 'Loading...',
|
url: 'Loading...',
|
||||||
@ -10,13 +13,20 @@
|
|||||||
visits: 'Loading...'
|
visits: 'Loading...'
|
||||||
};
|
};
|
||||||
$: urlVisists = [];
|
$: urlVisists = [];
|
||||||
|
let visitQuery;
|
||||||
|
|
||||||
|
const unsubscribe = UserStore.subscribe((value) => {
|
||||||
|
if (value.isLoggedIn) {
|
||||||
Apiclient.getUrlDetails(shortcode).then((res) => {
|
Apiclient.getUrlDetails(shortcode).then((res) => {
|
||||||
urlDetails = res;
|
urlDetails = res;
|
||||||
});
|
});
|
||||||
let visitQuery = Apiclient.getUrlVisits(shortcode).then((res) => {
|
visitQuery = Apiclient.getUrlVisits(shortcode).then((res) => {
|
||||||
urlVisists = res;
|
urlVisists = res;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(unsubscribe);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h2 class="text-3xl font-bold text-gray-800 dark:text-gray-100 pb-6">Details: {shortcode}</h2>
|
<h2 class="text-3xl font-bold text-gray-800 dark:text-gray-100 pb-6">Details: {shortcode}</h2>
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
<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;
|
||||||
|
|
||||||
|
const unsubscribe = UserStore.subscribe((value) => {
|
||||||
|
if (value.isLoggedIn) {
|
||||||
|
urlQuery = Apiclient.getUrls().then((res) => {
|
||||||
urls = res;
|
urls = res;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onDestroy(unsubscribe);
|
||||||
|
|
||||||
function deleteUrl(shortcode) {
|
function deleteUrl(shortcode) {
|
||||||
Apiclient.deleteUrl(shortcode).then(() => {
|
Apiclient.deleteUrl(shortcode).then(() => {
|
||||||
|
@ -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