28 lines
718 B
Vue
28 lines
718 B
Vue
<script setup>
|
|
import LoginForm from '../components/Login/LoginForm.vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { useAuthStore } from '../stores/auth';
|
|
import { login } from '../lib/api';
|
|
|
|
const router = useRouter();
|
|
const authStore = useAuthStore();
|
|
|
|
const onSubmit = async ({ username, password, hcaptchaResponse }) => {
|
|
try {
|
|
const response = await login(username, password, hcaptchaResponse);
|
|
const { jwt } = response;
|
|
authStore.setJwt(jwt);
|
|
alert('Login successful!');
|
|
router.push('/profile');
|
|
} catch (error) {
|
|
alert("Login failed: " + error.message);
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="ts-app-center">
|
|
<LoginForm @login-submit="onSubmit" />
|
|
</div>
|
|
</template>
|