2023-02-22 12:43:39 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import InputWithLabel from '../../components/forms/InputWithLabel.svelte';
|
|
|
|
import { getContext, onMount } from 'svelte';
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
let errors = { username_error: null, password_error: null };
|
|
|
|
let username = '';
|
|
|
|
let password = '';
|
|
|
|
|
|
|
|
const { login, isAuth, initialLoading } = getContext('auth');
|
|
|
|
console.log('TEST1', initialLoading, isAuth);
|
|
|
|
$: {
|
|
|
|
!$initialLoading && !!$isAuth && goto('/dashboard');
|
|
|
|
}
|
2023-02-26 17:12:10 +01:00
|
|
|
let loading = false
|
2023-02-22 12:43:39 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="parent">
|
|
|
|
<div>
|
|
|
|
<h1>Se connecter</h1>
|
|
|
|
<InputWithLabel
|
|
|
|
change={() => {
|
|
|
|
errors.username_error = null;
|
|
|
|
}}
|
|
|
|
type="text"
|
|
|
|
bind:value={username}
|
|
|
|
label="Nom d'utilisateur"
|
|
|
|
errors={errors.username_error != null ? [errors.username_error] : []}
|
|
|
|
/>
|
|
|
|
<InputWithLabel
|
|
|
|
change={() => {
|
|
|
|
errors.password_error = null;
|
|
|
|
}}
|
|
|
|
type="password"
|
|
|
|
bind:value={password}
|
|
|
|
label="Mot de passe"
|
|
|
|
errors={errors.password_error != null ? [errors.password_error] : []}
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
class="primary-btn"
|
|
|
|
on:click={() => {
|
2023-02-26 17:12:10 +01:00
|
|
|
loading = true;
|
|
|
|
login(username, password).then(()=>{loading=false}).catch((r) => {
|
2023-02-22 12:43:39 +01:00
|
|
|
errors = { ...errors, ...r.data.detail };
|
2023-02-26 17:12:10 +01:00
|
|
|
loading = false;
|
2023-02-22 12:43:39 +01:00
|
|
|
});
|
|
|
|
}}
|
|
|
|
|
|
|
|
>
|
2023-02-26 17:12:10 +01:00
|
|
|
{#if loading}
|
|
|
|
<span class="spinner" />
|
|
|
|
{:else}
|
|
|
|
Se connecter
|
|
|
|
{/if}
|
2023-02-22 12:43:39 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
h1 {
|
|
|
|
font-size: 4em;
|
|
|
|
}
|
|
|
|
.parent {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
margin-top: 50px;
|
|
|
|
div {
|
|
|
|
width: 40%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
gap: 20px;
|
|
|
|
}
|
|
|
|
}
|
2023-02-26 17:12:10 +01:00
|
|
|
.spinner{
|
|
|
|
width: 15px;
|
|
|
|
height: 15px;
|
|
|
|
border-width: 2px!important;
|
|
|
|
}
|
2023-02-22 12:43:39 +01:00
|
|
|
</style>
|