Added basic login call logic
This commit is contained in:
parent
5263d1974a
commit
0aab082b17
|
@ -43,4 +43,15 @@ export default class Apiclient {
|
|||
})
|
||||
).status;
|
||||
}
|
||||
|
||||
static async login(username, password) {
|
||||
return (
|
||||
await axios.post(`https://kauft.es/api/auth/login`, {
|
||||
auth: {
|
||||
username,
|
||||
password
|
||||
}
|
||||
})
|
||||
).data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
import Apiclient from '$lib/Apiclient';
|
||||
|
||||
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>
|
||||
|
||||
<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"
|
||||
placeholder="Username"
|
||||
aria-label="Username"
|
||||
value={username}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
@ -30,11 +44,12 @@
|
|||
type="password"
|
||||
placeholder="Password"
|
||||
aria-label="Password"
|
||||
value={password}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<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"
|
||||
type="button"
|
||||
>
|
Loading…
Reference in New Issue