Add frontend/src/views/LoginView.vue
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<div class="login">
|
||||
<h2>Login</h2>
|
||||
<form @submit.prevent="handleLogin">
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<input v-model="username" type="text" required />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input v-model="password" type="password" required />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
<p>Don't have an account? <router-link to="/register">Register</router-link></p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const username = ref('')
|
||||
const password = ref('')
|
||||
const authStore = useAuthStore()
|
||||
const router = useRouter()
|
||||
|
||||
const handleLogin = async () => {
|
||||
const success = await authStore.login(username.value, password.value)
|
||||
if (success) {
|
||||
router.push('/workspaces')
|
||||
} else {
|
||||
alert('Login failed')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user