✨ feat (auth): server side proxy login request
This commit is contained in:
@@ -1,22 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
// import PasswordInput from '~/components/PasswordInput.vue'
|
||||
import { Loader2 } from 'lucide-vue-next'
|
||||
|
||||
const email = ref('demo@gmail.com')
|
||||
const password = ref('password')
|
||||
const isLoading = ref(false)
|
||||
|
||||
function onSubmit(event: Event) {
|
||||
async function onSubmit(event: Event) {
|
||||
event.preventDefault()
|
||||
if (!email.value || !password.value) return
|
||||
|
||||
isLoading.value = true
|
||||
|
||||
setTimeout(() => {
|
||||
if (email.value === 'demo@gmail.com' && password.value === 'password') navigateTo('/')
|
||||
try {
|
||||
const { data: respData } = await useFetch('/api/v1/authentication/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
name: 'system',
|
||||
password: 'the-SYSTEM-1234',
|
||||
}),
|
||||
})
|
||||
|
||||
const resp = respData.value
|
||||
if (!resp) throw new Error('No response')
|
||||
|
||||
const { data: rawdata, meta } = resp
|
||||
console.log('DATA', rawdata)
|
||||
console.log('META', meta)
|
||||
|
||||
if (meta.status === 'verified') {
|
||||
await nextTick()
|
||||
navigateTo('/')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Login failed:', error)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user