messages added
This commit is contained in:
parent
c74032d1d0
commit
0e51451ad2
2 changed files with 41 additions and 6 deletions
|
|
@ -58,6 +58,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||
router.push({ name: 'collection'})
|
||||
} catch (error) {
|
||||
console.error('Login error:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,23 @@
|
|||
import { reactive, ref } from 'vue'
|
||||
import { useAuthStore } from '@/stores/authStore.js'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useMessage } from 'naive-ui'
|
||||
|
||||
const store = useAuthStore()
|
||||
const messages = useMessage()
|
||||
|
||||
const { activeTab } = storeToRefs(store)
|
||||
|
||||
const signInEmail = ref('')
|
||||
const signInPassword = ref('')
|
||||
|
||||
const onSignIn = () => {
|
||||
store.login(signInEmail.value, signInPassword.value)
|
||||
const onSignIn = async () => {
|
||||
try{
|
||||
await store.login(signInEmail.value, signInPassword.value)
|
||||
messages.success('Login success')
|
||||
} catch (error) {
|
||||
messages.error("Login error")
|
||||
}
|
||||
}
|
||||
|
||||
const signUp = reactive({
|
||||
|
|
@ -20,8 +27,35 @@ const signUp = reactive({
|
|||
reenterPassword: '',
|
||||
})
|
||||
|
||||
const onSignUp = () => {
|
||||
store.register(signUp.email, signUp.password)
|
||||
const onSignUp = async () => {
|
||||
if (!signUp.email.trim()) {
|
||||
messages.error('Email is required')
|
||||
return
|
||||
}
|
||||
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
if (!emailRegex.test(signUp.email)) {
|
||||
messages.error('Please enter a valid email address')
|
||||
return
|
||||
}
|
||||
|
||||
if (!signUp.password.trim()) {
|
||||
messages.error('Password is required')
|
||||
return
|
||||
}
|
||||
|
||||
if (signUp.password !== signUp.reenterPassword) {
|
||||
messages.error('Passwords do not match')
|
||||
return
|
||||
}
|
||||
|
||||
try{
|
||||
await store.register(signUp.email, signUp.password)
|
||||
messages.success('Register success')
|
||||
activeTab.value = 'signin'
|
||||
} catch (error) {
|
||||
messages.error("Register error")
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -43,7 +77,7 @@ const onSignUp = () => {
|
|||
<n-form-item-row label="Password">
|
||||
<n-input v-model:value="signInPassword" type="password" show-password-on="click" />
|
||||
</n-form-item-row>
|
||||
<n-button type="primary" block secondary strong attr-type="submit" @click="onSignIn"> Sign In</n-button>
|
||||
<n-button type="primary" block secondary strong attr-type="submit"> Sign In</n-button>
|
||||
</n-form>
|
||||
</n-tab-pane>
|
||||
|
||||
|
|
@ -58,7 +92,7 @@ const onSignUp = () => {
|
|||
<n-form-item-row label="Reenter Password">
|
||||
<n-input type="password" v-model:value="signUp.reenterPassword" show-password-on="click" />
|
||||
</n-form-item-row>
|
||||
<n-button type="primary" block secondary strong attr-type="submit" @click="onSignUp">Sign up</n-button>
|
||||
<n-button type="primary" block secondary strong attr-type="submit">Sign up</n-button>
|
||||
</n-form>
|
||||
</n-tab-pane>
|
||||
</n-tabs>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue