🐐
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
<script>
|
||||
import Card from "$lib/Card.svelte";
|
||||
import { goto } from '$app/navigation';
|
||||
import { onMount } from 'svelte';
|
||||
import Card from '$lib/Card.svelte';
|
||||
|
||||
let cards = $state([]);
|
||||
let loading = $state(false);
|
||||
|
||||
onMount(() => {
|
||||
if (!localStorage.getItem('token')) goto('/auth');
|
||||
});
|
||||
|
||||
async function openPack() {
|
||||
loading = true;
|
||||
try {
|
||||
const res = await fetch("http://localhost:8000/pack/14");
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
cards = await res.json();
|
||||
} catch (e) {
|
||||
console.error("Failed to open pack:", e);
|
||||
} finally {
|
||||
loading = false;
|
||||
loading = true;
|
||||
try {
|
||||
const res = await fetch('http://localhost:8000/pack/10', {
|
||||
headers: { Authorization: `Bearer ${localStorage.getItem('token')}` }
|
||||
});
|
||||
if (res.status === 401) { goto('/auth'); return; }
|
||||
cards = await res.json();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
@@ -33,7 +41,7 @@
|
||||
<style>
|
||||
main {
|
||||
min-height: 100vh;
|
||||
background: #0d0a04;
|
||||
background: #887859;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user