Merge stable version before large change #16
@ -46,7 +46,7 @@ import { createUserWithEmailAndPassword, signInWithEmailAndPassword, sendPasswor
|
|||||||
import { doc, setDoc } from "firebase/firestore";
|
import { doc, setDoc } from "firebase/firestore";
|
||||||
|
|
||||||
|
|
||||||
const { auth, db } = inject('firebase')
|
const { auth, db, userAllPersons } = inject('firebase')
|
||||||
|
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
|
||||||
@ -67,30 +67,23 @@ const submitLoginForm = () => {
|
|||||||
signInWithEmailAndPassword(auth.value, form.value.email, form.value.password)
|
signInWithEmailAndPassword(auth.value, form.value.email, form.value.password)
|
||||||
.then(() => disableButtons.value = false)
|
.then(() => disableButtons.value = false)
|
||||||
.catch(async (error) => {
|
.catch(async (error) => {
|
||||||
const errorCode = error.code;
|
|
||||||
const errorMessage = error.message;
|
|
||||||
|
|
||||||
if (error.code === 'auth/user-not-found') {
|
if (error.code === 'auth/user-not-found') {
|
||||||
|
const { error: err, data } = await useFetch('/api/checkrelatiecode', {
|
||||||
fetch('https://api.xeovalyte.com/checkrelatiecode', {
|
method: 'post',
|
||||||
method: 'POST',
|
body: { email: form.value.email, relatiecode: form.value.password.toUpperCase() }
|
||||||
headers: {
|
|
||||||
Authorization: 'Basic WGVvdmFseXRlOmtNKjhuRXMzNTchalJlXm1KYnZrRSFOIw==',
|
|
||||||
'content-type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ email: form.value.email, relatiecode: form.value.password.toUpperCase() })
|
|
||||||
}).then(response => response.json())
|
|
||||||
.then(response => {
|
|
||||||
disableButtons.value = false
|
|
||||||
if (response.code === 'incorrect') return toast.error('Email, wachtwoord of relatiecode onjuist')
|
|
||||||
else if (response.code === 'correct') return creatingAccount.value = true
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
disableButtons.value = false
|
|
||||||
console.log(err)
|
|
||||||
|
|
||||||
toast.error('Error met het controleren van relatiecode')
|
if (err.value) {
|
||||||
});
|
console.log(err.value)
|
||||||
|
disableButtons.value = false
|
||||||
|
return toast.error('Error tijdens het controleren van relatiecode')
|
||||||
|
}
|
||||||
|
|
||||||
|
disableButtons.value = false
|
||||||
|
if (data.value.code === 'incorrect') return toast.error('Email, wachtwoord of relatiecode onjuist')
|
||||||
|
else if (data.value.code === 'correct') return creatingAccount.value = true
|
||||||
|
|
||||||
} else if (error.code === 'auth/wrong-password') {
|
} else if (error.code === 'auth/wrong-password') {
|
||||||
toast.error('Verkeerde wachtwoord')
|
toast.error('Verkeerde wachtwoord')
|
||||||
} else {
|
} else {
|
||||||
@ -109,37 +102,43 @@ const submitCreateForm = () => {
|
|||||||
disableButtons.value = true
|
disableButtons.value = true
|
||||||
|
|
||||||
createUserWithEmailAndPassword(auth.value, form.value.email, form.value.newPassword)
|
createUserWithEmailAndPassword(auth.value, form.value.email, form.value.newPassword)
|
||||||
.then((userCredential) => {
|
.then(async (userCredential) => {
|
||||||
fetch('https://api.xeovalyte.com/getrelatiecodes', {
|
const idToken = await auth.value.currentUser.getIdToken(true)
|
||||||
method: 'POST',
|
const { error, data } = await useFetch('/api/getrelatiecodes', {
|
||||||
headers: {
|
method: 'post',
|
||||||
Authorization: 'Basic WGVvdmFseXRlOmtNKjhuRXMzNTchalJlXm1KYnZrRSFOIw==',
|
body: { email: form.value.email, token: idToken }
|
||||||
'content-type': 'application/json'
|
})
|
||||||
},
|
|
||||||
body: JSON.stringify({ email: form.value.email })
|
if (error.value) {
|
||||||
}).then(response => response.json())
|
console.log(error.value)
|
||||||
.then(response => {
|
|
||||||
disableButtons.value = false
|
disableButtons.value = false
|
||||||
if (response.code === 'error') return toast.error('Error tijdens maken van account')
|
return toast.error('Error tijdens het controleren van relatiecode')
|
||||||
else if (response.code === 'success') {
|
}
|
||||||
setDoc(doc(db, "users", userCredential.user.uid), {
|
|
||||||
|
disableButtons.value = false
|
||||||
|
if (data.value.code === 'error') return toast.error('Error tijdens maken van account')
|
||||||
|
else if (data.value.code === 'success') {
|
||||||
|
await setDoc(doc(db, "users", userCredential.user.uid), {
|
||||||
email: form.value.email,
|
email: form.value.email,
|
||||||
relatiecodes: [form.value.password.toUpperCase()],
|
relatiecodes: [form.value.password.toUpperCase()],
|
||||||
allRelatiecodes: response.relatiecodes,
|
allRelatiecodes: data.value.relatiecodes,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.relatiecodes.length > 1) {
|
data.value.persons.forEach(person => {
|
||||||
|
if (person.relatiecode === form.value.password.toUpperCase()) {
|
||||||
|
person.checked = true
|
||||||
|
} else {
|
||||||
|
person.checked = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
userAllPersons.value = data.value.persons
|
||||||
|
|
||||||
|
if (data.value.relatiecodes.length > 1) {
|
||||||
return navigateTo('/settings/config/managerelatiecodes')
|
return navigateTo('/settings/config/managerelatiecodes')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
|
||||||
disableButtons.value = false
|
|
||||||
console.log(err)
|
|
||||||
|
|
||||||
toast.error('Error met het controleren van relatiecode')
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
const errorCode = error.code;
|
const errorCode = error.code;
|
||||||
const errorMessage = error.message;
|
const errorMessage = error.message;
|
||||||
@ -173,7 +172,6 @@ const goBack = () => {
|
|||||||
newPassword: '',
|
newPassword: '',
|
||||||
confirmNewPassword: ''
|
confirmNewPassword: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user