Merge stable version before large change #16

Merged
xeovalyte merged 28 commits from dev into main 2023-02-14 15:37:45 +01:00
2 changed files with 146 additions and 148 deletions
Showing only changes of commit 76fec72868 - Show all commits

View File

@ -46,7 +46,7 @@ import { createUserWithEmailAndPassword, signInWithEmailAndPassword, sendPasswor
import { doc, setDoc } from "firebase/firestore";
const { auth, db } = inject('firebase')
const { auth, db, userAllPersons } = inject('firebase')
const toast = useToast()
@ -67,30 +67,23 @@ const submitLoginForm = () => {
signInWithEmailAndPassword(auth.value, form.value.email, form.value.password)
.then(() => disableButtons.value = false)
.catch(async (error) => {
const errorCode = error.code;
const errorMessage = error.message;
if (error.code === 'auth/user-not-found') {
fetch('https://api.xeovalyte.com/checkrelatiecode', {
method: 'POST',
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
const { error: err, data } = await useFetch('/api/checkrelatiecode', {
method: 'post',
body: { email: form.value.email, relatiecode: form.value.password.toUpperCase() }
})
.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') {
toast.error('Verkeerde wachtwoord')
} else {
@ -109,37 +102,43 @@ const submitCreateForm = () => {
disableButtons.value = true
createUserWithEmailAndPassword(auth.value, form.value.email, form.value.newPassword)
.then((userCredential) => {
fetch('https://api.xeovalyte.com/getrelatiecodes', {
method: 'POST',
headers: {
Authorization: 'Basic WGVvdmFseXRlOmtNKjhuRXMzNTchalJlXm1KYnZrRSFOIw==',
'content-type': 'application/json'
},
body: JSON.stringify({ email: form.value.email })
}).then(response => response.json())
.then(response => {
.then(async (userCredential) => {
const idToken = await auth.value.currentUser.getIdToken(true)
const { error, data } = await useFetch('/api/getrelatiecodes', {
method: 'post',
body: { email: form.value.email, token: idToken }
})
if (error.value) {
console.log(error.value)
disableButtons.value = false
if (response.code === 'error') return toast.error('Error tijdens maken van account')
else if (response.code === 'success') {
setDoc(doc(db, "users", userCredential.user.uid), {
return toast.error('Error tijdens het controleren van relatiecode')
}
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,
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')
}
}
})
.catch(err => {
disableButtons.value = false
console.log(err)
toast.error('Error met het controleren van relatiecode')
});
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
@ -173,7 +172,6 @@ const goBack = () => {
newPassword: '',
confirmNewPassword: ''
}
}
</script>