[] Errors

This commit is contained in:
Anthony 2022-11-24 15:42:10 +00:00
parent b881a650a6
commit bad1c5b8d7
2 changed files with 20 additions and 14 deletions

View File

@ -113,7 +113,6 @@
<input type="password" class="form-control" id="account-confirm-password">
</div>
</form>
<div id="login-error"></div>
<div id="verification-alert"></div>
<ul id="login-list">
<li>Loading OAuth2 providers...</li>

View File

@ -87,17 +87,24 @@ async function prepareLoginModal(register: boolean) {
"name": document.querySelector<HTMLInputElement>('#account-username')!.value,
}
await pb.collection('users').create(data);
await pb.collection('users').requestVerification(data.email)
$('#verification-alert').html(`
await pb.collection('users').create(data).then(async () => {
await pb.collection('users').requestVerification(data.email).then(() => $('#verification-alert').html(`
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Verification email sent!</strong> Please check your inbox and click the link to verify your email address.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`))
})
.catch((err) => {
prepareLoginModal(false)
$('#verification-alert').html(`
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> ${err}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`)
})
})
} else {
document.querySelector<HTMLHeadingElement>('#loginModalLabel')!.innerText = 'Login to your Apexie ID'
document.querySelector<HTMLDivElement>('#loginModalFooter')!.innerHTML = `
@ -110,9 +117,13 @@ async function prepareLoginModal(register: boolean) {
document.querySelector<HTMLDivElement>('#account-confirm-password-fill')!.hidden = !register
document.getElementById('account-register')!.addEventListener('click', () => prepareLoginModal(true))
document.getElementById('account-login')!.addEventListener('click', async () => {
login_error.innerHTML = ''
await pb.collection('users').authWithPassword((<HTMLInputElement>document.getElementById('account-email')!).value, (<HTMLInputElement>document.getElementById('account-password')!).value).catch(() => {
login_error.innerHTML = 'Failed to authenticate. Please try again.<p>'
await pb.collection('users').authWithPassword((<HTMLInputElement>document.getElementById('account-email')!).value, (<HTMLInputElement>document.getElementById('account-password')!).value).catch((err) => {
$('#verification-alert').html(`
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> ${err}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`)
document.querySelector<HTMLInputElement>('#account-password')!.value = ''
})
})
@ -122,10 +133,6 @@ async function prepareLoginModal(register: boolean) {
document.getElementById('login_button')!.addEventListener('click', () => prepareLoginModal(false))
let login_error = document.querySelector<HTMLDivElement>('#login-error')!
if (!gdprConsent) {
gdprConsentModal.show()
const gdprConsentButton = document.getElementById("gdpr-button")!