update: separate login logic to loginview

This commit is contained in:
Tony Yang
2025-04-15 11:00:39 +08:00
parent a54c8b0fba
commit d227288d14
2 changed files with 26 additions and 19 deletions
+20 -3
View File
@@ -1,10 +1,27 @@
<script setup>
import LoginForm from '../components/Login/LoginForm.vue';
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 }) => {
try {
const response = await login(username, password);
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 />
<LoginForm @login-submit="onSubmit" />
</div>
</template>