update: separate login logic to loginview
This commit is contained in:
+20
-3
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user