Added basic login call logic
This commit is contained in:
parent
5263d1974a
commit
0aab082b17
@ -43,4 +43,15 @@ export default class Apiclient {
|
|||||||
})
|
})
|
||||||
).status;
|
).status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async login(username, password) {
|
||||||
|
return (
|
||||||
|
await axios.post(`https://kauft.es/api/auth/login`, {
|
||||||
|
auth: {
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
}
|
||||||
|
})
|
||||||
|
).data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
7
src/routes/login/__layout.reset.svelte
Normal file
7
src/routes/login/__layout.reset.svelte
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
import '../../app.postcss';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="bg-white dark:bg-gray-800 h-screen">
|
||||||
|
<slot />
|
||||||
|
</div>
|
@ -1,7 +1,20 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import Apiclient from '$lib/Apiclient';
|
||||||
|
|
||||||
import UserStore from '$lib/UserStore';
|
import UserStore from '$lib/UserStore';
|
||||||
|
|
||||||
$: logged_in = $UserStore.isLoggedIn;
|
$: username = "";
|
||||||
|
$: password = "";
|
||||||
|
|
||||||
|
async function login() {
|
||||||
|
let login = await Apiclient.login(username, password);
|
||||||
|
if (login.status != 200 && login.status != 201) {
|
||||||
|
error = login.message;
|
||||||
|
} else {
|
||||||
|
UserStore.login(login);
|
||||||
|
location.replace("/");
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-full max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800">
|
<div class="w-full max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800">
|
||||||
@ -21,6 +34,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Username"
|
placeholder="Username"
|
||||||
aria-label="Username"
|
aria-label="Username"
|
||||||
|
value={username}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -30,11 +44,12 @@
|
|||||||
type="password"
|
type="password"
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
aria-label="Password"
|
aria-label="Password"
|
||||||
|
value={password}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex items-center justify-between mt-4">
|
<div class="flex items-center justify-between mt-4">
|
||||||
<button
|
<button on:click={login}
|
||||||
class="px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none"
|
class="px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
Loading…
x
Reference in New Issue
Block a user