diff --git a/resources/js/app.js b/resources/js/app.js index ba6fb41..a02973a 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -7,7 +7,7 @@ import './bootstrap'; document.addEventListener('alpine:init', () => { Alpine.data('authForm', () => ({ - mode: 'register', + mode: 'login', username: '', name: '', browserSupported: browserSupportsWebAuthn(), @@ -15,11 +15,11 @@ document.addEventListener('alpine:init', () => { submit() { this.error = null; - if (this.mode === 'register') { - return this.submitRegister(); + if (this.mode === 'login') { + return this.submitLogin(); } - return this.submitLogin(); + return this.submitRegister(); }, submitRegister() { window.axios @@ -58,6 +58,14 @@ document.addEventListener('alpine:init', () => { 'Something went wrong verifying the authentication.'; }) .catch((error) => { + const errorMessage = + error?.response?.data?.message || error; + + if (errorMessage === 'User not found') { + this.mode = 'confirmRegistration'; + return; + } + this.error = error?.response?.data?.message || error; }); }, diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 9e07085..abe8925 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -31,10 +31,9 @@