wallet.andert.me/src/lib/User.svelte

28 lines
563 B
Svelte
Raw Normal View History

2023-08-25 12:59:02 +00:00
<script>
import { onMount } from "svelte";
import Cookies from "js-cookie";
let user = null;
onMount(async () => {
const token = Cookies.get("token");
const response = await fetch("/api/auth/session", {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (response.ok) {
user = await response.json();
} else {
console.error("Failed to fetch user data");
}
});
</script>
{#if user}
<p>Welcome, {user.name}!</p>
<p>Your roles: {user.roles.join(", ")}</p>
2023-08-25 12:59:02 +00:00
{:else}
<p>Loading...</p>
{/if}