34 lines
1.1 KiB
Svelte
34 lines
1.1 KiB
Svelte
<script>
|
|
import PocketBase from 'pocketbase';
|
|
import Input from '$lib/components/base/Input.svelte';
|
|
import { setContext } from 'svelte';
|
|
|
|
const pb = new PocketBase('http://localhost:8090');
|
|
|
|
async function login(form) {
|
|
const formData = new FormData(form.target)
|
|
const data = {};
|
|
for (let field of formData) {
|
|
const [key, value] = field;
|
|
data[key] = value;
|
|
}
|
|
console.log(data)
|
|
try {
|
|
const authData = await pb.collection('users').authWithPassword(data.email, data.password);
|
|
console.log(authData)
|
|
console.log(pb.authStore.token);
|
|
window.location.href = "/"
|
|
} catch (err) {
|
|
console.log("Failed to log");
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
<div class="flex flex-col items-center mt-32 h-full">
|
|
<form class="flex flex-col gap-4 w-lg" on:submit|preventDefault={(e) => login(e)}>
|
|
<Input name="email" placeholder="email" type="email" />
|
|
<Input name="password" placeholder="password" type="password" />
|
|
<button class="border rounded p-2 bg-gray-800 text-white hover:bg-gray-700">Connexion</button>
|
|
</form>
|
|
</div>
|