|
|
@@ -0,0 +1,61 @@
|
|
|
+<script>
|
|
|
+ import { onMount } from 'svelte';
|
|
|
+ import { authentication } from '../store.js';
|
|
|
+ import { fade } from 'svelte/transition';
|
|
|
+ import { goto } from '$app/navigation';
|
|
|
+
|
|
|
+ let isAuthenticated = false;
|
|
|
+ let isLoading = true;
|
|
|
+ let user = null;
|
|
|
+
|
|
|
+ $: authentication.subscribe((value) => {
|
|
|
+ isAuthenticated = !!value;
|
|
|
+ if (value) {
|
|
|
+ user = value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ onMount(() => {
|
|
|
+ try {
|
|
|
+ const storedAuth = localStorage.getItem('authentication');
|
|
|
+ if (storedAuth) {
|
|
|
+ authentication.set(JSON.parse(storedAuth));
|
|
|
+ } else {
|
|
|
+ goto('/login');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error parsing stored auth:', error);
|
|
|
+ } finally {
|
|
|
+ isLoading = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function logout() {
|
|
|
+ window.location.href = '/logout';
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<svelte:head>
|
|
|
+ <title>Login</title>
|
|
|
+ <meta name="description" content="Login page" />
|
|
|
+</svelte:head>
|
|
|
+
|
|
|
+<div in:fade class="text-column">
|
|
|
+ {#if isLoading}
|
|
|
+ <p>Loading...</p>
|
|
|
+ {:else if isAuthenticated}
|
|
|
+ <p>You are logged in as {user.username}!</p>
|
|
|
+ <button class="logout-button" on:click={logout}>Logout</button>
|
|
|
+ {/if}
|
|
|
+</div>
|
|
|
+
|
|
|
+<style>
|
|
|
+ input::placeholder {
|
|
|
+ opacity: 0.5;
|
|
|
+ }
|
|
|
+
|
|
|
+ .logout-button {
|
|
|
+ background-color: #f44336;
|
|
|
+ color: white;
|
|
|
+ }
|
|
|
+</style>
|