This commit is contained in:
parent
50d03a5387
commit
542d8583ab
@ -1,6 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { adminLogin } from '$lib/api';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import session from '$lib/session.svelte';
|
||||
|
||||
let username = '';
|
||||
let password = '';
|
||||
let errorMessage = '';
|
||||
@ -14,7 +16,14 @@
|
||||
|
||||
try {
|
||||
const token = await adminLogin({ username, password });
|
||||
dispatch('login', { token }); // Dispatch the token to the parent component or handle it here
|
||||
|
||||
// Store session data
|
||||
session.login({
|
||||
username,
|
||||
password_hash: token // Assuming the token acts as a password hash for session purposes
|
||||
});
|
||||
|
||||
dispatch('login', { username, token });
|
||||
alert('Login successful!');
|
||||
} catch (error: any) {
|
||||
errorMessage = error.message || 'Login failed. Please try again.';
|
||||
@ -52,10 +61,6 @@
|
||||
{#if errorMessage}
|
||||
<div class="error-message">{errorMessage}</div>
|
||||
{/if}
|
||||
|
||||
{#if loading}
|
||||
<div class="loading">Loading...</div>
|
||||
{/if}
|
||||
</form>
|
||||
|
||||
<style>
|
||||
@ -95,11 +100,4 @@
|
||||
font-size: 14px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user