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