Untitled

 avatar
unknown
javascript
5 months ago
951 B
1
Indexable
import { defineStore } from 'pinia'

export const useLoginStore = defineStore({
    id: 'login',
    state: () => {
        return {
            form: {
                email: undefined,
                password: undefined
            },
            loading: false
        }
    },
    actions: {
        async onSubmit(form) {
            const { signIn } = useAuth()

            this.loading = true
            try {
                await signIn(
                    {
                        email: this.form.email,
                        password: this.form.password
                    },
                    { callbackUrl: '/earn' }
                )

                this.$reset()
            } catch ({ response: { _data } }) {
                form.setErrors(_data.errors)
            }
            this.loading = false
        }
    }
})

if (import.meta.hot) {
    import.meta.hot.accept(acceptHMRUpdate(useLoginStore, import.meta.hot))
}
Editor is loading...
Leave a Comment