Created
October 5, 2023 03:20
-
-
Save YonatanKra/a4c019b62f7ed7e59c50bb927ee53b06 to your computer and use it in GitHub Desktop.
Tauri-demo: display alert when user logs in but not verified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should display an alert if user is logged in and email not verified', () => { | |
app.connectedCallback(); | |
authComponent.isUserEmailVerified.mockReturnValue(false); | |
const spy = vi.spyOn(app, 'alert'); | |
setLoginStatus(true); | |
expect(spy).toHaveBeenCalledWith({message: 'Please verify your email address', title: 'Email not verified'}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#setViewAccordingToUserStatus = () => { | |
const isAuthComponentSet = !!this.#authComponent!.isLoggedIn; | |
const isLoggedIn = isAuthComponentSet && this.#authComponent!.isLoggedIn?.(); | |
const isUserEmailVerified = isAuthComponentSet && this.#authComponent!.isUserEmailVerified?.(); | |
if (isLoggedIn && isUserEmailVerified === false) { | |
this.#authComponent!.logout(); | |
this.alert({message: 'Please verify your email address', title: 'Email not verified'}); | |
return; | |
} | |
if (!isAuthComponentSet || !isLoggedIn) { | |
this.#loginButton.setAttribute('slot', 'hidden'); | |
this.#mainContent.innerHTML = `<yag-login></yag-login>`; | |
this.#setLoginListener(); | |
} else { | |
this.#loginButton.setAttribute('slot', 'action-items'); | |
this.#unsetLoginListener(); | |
this.#mainContent.innerHTML = `<yag-greeter></yag-greeter>`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment