From f4cfd1a2658ac9180db5810062875dce5ad5ba02 Mon Sep 17 00:00:00 2001 From: Joe Tannenbaum Date: Fri, 13 Jan 2023 14:21:42 -0500 Subject: [PATCH] better flow --- resources/js/app.js | 16 ++++++++++++---- resources/views/home.blade.php | 26 ++++++++------------------ 2 files changed, 20 insertions(+), 22 deletions(-) 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 @@

- Register - Sign In + Sign In or Register

-
+

-
- Already have an account? - - Sign in. - -
- -
- No account? - - Register now. - +
+

No account exists for "". Do you want to create a new account?

+

+ Cancel +