Fix: Authentification to use deployed URL rather than localhost

This commit is contained in:
zuma 2025-04-16 18:14:37 +02:00
parent dd32378294
commit 54337509cf

View file

@ -1,10 +1,16 @@
<script> <script>
import PocketBase from 'pocketbase'; import PocketBase from 'pocketbase';
import Input from '$lib/components/base/Input.svelte'; import Input from '$lib/components/base/Input.svelte';
import { setContext } from 'svelte'; import Button from '$lib/components/base/Button.svelte';
import Button from '$lib/components/base/Button.svelte'; import { onMount } from 'svelte';
const pb = new PocketBase('http://localhost:8090'); let pb
let error = $state("")
onMount(() => {
pb = new PocketBase(window.location.origin)
})
async function login(form) { async function login(form) {
const formData = new FormData(form.target) const formData = new FormData(form.target)
@ -20,6 +26,7 @@
console.log(pb.authStore.token); console.log(pb.authStore.token);
window.location.href = "/" window.location.href = "/"
} catch (err) { } catch (err) {
error = err.toString()
console.log("Failed to log"); console.log("Failed to log");
} }
} }
@ -27,9 +34,12 @@
</script> </script>
<div class="flex flex-col items-center mt-32 h-full p-8"> <div class="flex flex-col items-center mt-32 h-full p-8">
<form class="flex flex-col gap-4 max-w-lg w-full" on:submit|preventDefault={(e) => login(e)}> <form class="flex flex-col gap-4 max-w-lg w-full" onsubmit={(e) => {e.preventDefault(); login(e)}}>
<Input name="email" placeholder="email" type="email" /> <Input name="email" placeholder="email" type="email" />
<Input name="password" placeholder="password" type="password" /> <Input name="password" placeholder="password" type="password" />
{#if error != ""}
<span class="bg-red-200 text-sm rounded-md p-2">{error}</span>
{/if}
<Button>Connexion</Button> <Button>Connexion</Button>
</form> </form>
</div> </div>