diff --git a/src/lib/api/auth.ts b/src/lib/api/auth.ts
index feb5bb62..7d45ce3f 100644
--- a/src/lib/api/auth.ts
+++ b/src/lib/api/auth.ts
@@ -52,6 +52,10 @@ export const createAuthObserver = (): Unsubscribe => {
let routeTo: string | null = null;
if (firebaseUser) {
+ if (oldStoredUser && oldStoredUser.uid !== firebaseUser.uid) {
+ console.info('The Firebase account was changed.');
+ }
+
// If already logged in
const firebaseUserEmailVerified: boolean = firebaseUser.emailVerified;
// This is undocumented, but it gets set, and it is used to check whether the email was verified in
@@ -97,10 +101,8 @@ export const createAuthObserver = (): Unsubscribe => {
console.log('Email verification full sync success - storing new user');
isVerifying = false;
newStoredUser = await storeNewUser();
- if (!isActiveContains(get(page), routes.ACCOUNT)) {
- // - demo-test auth will already be on /account
- // - staging/production auth will be on auth/action,
- // if it has not already been redirected by the continueUrl redirector.
+ if (isActiveContains(get(page), routes.AUTH_ACTION)) {
+ // If we're not on a useful page, redirect to /account
routeTo = routes.ACCOUNT;
}
} else {
@@ -144,6 +146,22 @@ export const createAuthObserver = (): Unsubscribe => {
};
};
+export const checkAndHandleUnverified = async (message?: string, timeout = 8000) => {
+ if (!get(user)?.emailVerified) {
+ // Migitates https://github.com/WelcometoMyGarden/welcometomygarden/issues/297
+ await auth().currentUser?.reload();
+ // Note: we check the currentUser.emailVerified prop here, because that is the only
+ // one that is atomically set after the .reload()
+ // It's enough signal to not show the warning, but for functionality,
+ // $user.emailVerified should still be checked before rendering content
+ // or taking actions that require full token verification.
+ if (!auth().currentUser?.emailVerified) {
+ notify.warning(message ?? get(_)('auth.verification.unverified'), timeout);
+ return goto(routes.ACCOUNT);
+ }
+ }
+};
+
export const isEmailVerifiedAndTokenSynced = async () => {
const currentUser = auth().currentUser;
const firebaseUserEmailVerified: boolean = currentUser?.emailVerified ?? false;
diff --git a/src/lib/components/Garden/Form.svelte b/src/lib/components/Garden/Form.svelte
index 01196d1f..9144a053 100644
--- a/src/lib/components/Garden/Form.svelte
+++ b/src/lib/components/Garden/Form.svelte
@@ -19,6 +19,7 @@
waterIcon,
tentIcon
} from '$lib/images/icons';
+ import ReloadSuggestion from '../ReloadSuggestion.svelte';
const dispatch = createEventDispatcher();
@@ -172,6 +173,7 @@
)}`
}
})}
+
diff --git a/src/lib/components/ReloadSuggestion.svelte b/src/lib/components/ReloadSuggestion.svelte new file mode 100644 index 00000000..2a6628e7 --- /dev/null +++ b/src/lib/components/ReloadSuggestion.svelte @@ -0,0 +1,35 @@ + + +
+ {@html $_('account.verify.reload-suggestion', { + values: { + reloading: `${$_('account.verify.reloading-text')}` + } + })} +
+ + diff --git a/src/lib/routes.js b/src/lib/routes.js index b19bf784..eb49711b 100644 --- a/src/lib/routes.js +++ b/src/lib/routes.js @@ -3,6 +3,7 @@ export default { ADD_GARDEN: '/garden/add', ABOUT_SUPERFAN: '/about-superfan', ABOUT_US: '/about-us', + AUTH_ACTION: '/auth/action', BECOME_SUPERFAN: '/become-superfan', CHAT: '/chat', COOKIE_POLICY: '/terms/cookies', diff --git a/src/locales/en.json b/src/locales/en.json index e017669b..96d958d8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -622,7 +622,8 @@ "title": "Add your garden" }, "manage": { - "title": "Manage garden" + "title": "Manage garden", + "add-first": "Please add a garden first." }, "form": { "title": "Add your garden to the map", @@ -954,7 +955,9 @@ "title": "Verify your email", "text": "You need to verify your email address if you want to chat or add a garden.", "button": "Resend email", - "sent": "Email sent!" + "sent": "Email sent!", + "reload-suggestion": "Did you already verify? Try {reloading} the page.", + "reloading-text": "reloading" }, "preferences": { "title": "Email preferences", @@ -993,12 +996,15 @@ "password": { "expired": "This password reset link has expired. Please request a new one" }, + "unsigned": "Please sign in first.", "verification": { "verifying": "Verifying your email address... Don't close this page, this could take a few seconds.", + "reloading": "Reloading your account...", "success": "Your email address was verified successfully!", "refresh": "Your email has already been verified.", "expired": "This verification link has expired. Please request a new one.", - "unsigned": "Please sign in first" + "sign-in": "Sign in to continue.", + "unverified": "Please verify your email first." }, "logged-out": "You have been logged out elsewhere. Please log in again." }, diff --git a/src/locales/fr.json b/src/locales/fr.json index cfe81e31..2a718a0f 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -677,7 +677,8 @@ "title": "Ajoutez votre jardin" }, "manage": { - "title": "Gérer le jardin" + "title": "Gérer le jardin", + "add-first": "Veuillez d'abord ajouter votre jardin" } }, "sign-in": { @@ -976,7 +977,9 @@ "title": "Confirmez votre adresse électronique", "sent": "Courriel envoyé !", "button": "Renvoyer le courriel", - "text": "Vous devez vérifier votre adresse électronique si vous voulez discuter ou ajouter un jardin." + "text": "Vous devez vérifier votre adresse électronique si vous voulez discuter ou ajouter un jardin.", + "reload-suggestion": "Avez vous déjà verifié? Essaye de {reloading} la page.", + "reloading-text": "recharger" }, "preferences": { "text": "M'envoyer des courriels quand :", @@ -987,12 +990,15 @@ "title": "Compte" }, "auth": { + "unsigned": "Veuillez vous inscrire d'abord.", "verification": { "verifying": "Vérification de votre email en cours... Merci de ne pas fermer cette page, cela peut prendre quelques secondes.", + "reloading": "Rechargement de votre compte en cours...", "refresh": "Votre adresse électronique a déjà été vérifié.", "success": "Votre adresse électronique a été vérifiée avec succès !", "expired": "Ce lien de vérification a expiré. Veuillez en demander un nouveau.", - "unsigned": "Veuillez vous inscrire d'abord" + "sign-in": "Veuillez vous inscrire pour continuer.", + "unverified": "Veuillez vérifier voter adresse électronique d'abord." }, "password": { "expired": "Ce lien de réinitialisation du mot de passe a expiré. Veuillez en demander un nouveau" diff --git a/src/locales/nl.json b/src/locales/nl.json index cc5653da..e3ecf466 100644 --- a/src/locales/nl.json +++ b/src/locales/nl.json @@ -185,7 +185,8 @@ "title": "Voeg jouw tuin toe" }, "manage": { - "title": "Beheer jouw tuin" + "title": "Beheer jouw tuin", + "add-first": "Voeg eerst jouw tuin toe." }, "form": { "title": "Voeg jouw tuin toe aan de kaart", @@ -517,7 +518,9 @@ "title": "Bevestig jouw e-mail", "text": "Je moet jouw e-mailadres controleren als je wilt chatten of een tuin wilt toevoegen.", "button": "E-mail opnieuw versturen", - "sent": "E-mail verzonden!" + "sent": "E-mail verzonden!", + "reload-suggestion": "Heb je al geverifieerd? Probeer de pagina te {reloading}.", + "reloading-text": "herladen" }, "preferences": { "title": "E-mail voorkeuren", @@ -556,12 +559,15 @@ "password": { "expired": "De link om jouw wachtwoord te herstellen is verlopen, probeer nog eens." }, + "unsigned": "Gelieve eerst in te loggen", "verification": { "verifying": "Je e-mailadres wordt geverifieerd... Gelieve deze pagina niet te sluiten, dit kan enkele seconden duren.", + "reloading": "Je account wordt herladen...", "success": "Jouw e-mailadres is met succes geverifieerd!", "refresh": "Jouw e-mail is al geverifieerd.", "expired": "Deze verificatielink is vervallen. Vraag een nieuwe aan.", - "unsigned": "Gelieve eerst in te loggen" + "sign-in": "Log in om verder te gaan.", + "unverified": "Gelieve eerst je email te verifiëren." } }, "register": { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 3be79373..e072b515 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -39,10 +39,12 @@ let vh = `0px`; + // Manage chat observers user.subscribe(async (tempUser) => { if (!unsubscribeFromChatObserver && tempUser && tempUser.emailVerified) unsubscribeFromChatObserver = await createChatObserver(tempUser.uid); + // Unsubscribe if the user logged out if (unsubscribeFromChatObserver && !tempUser) unsubscribeFromChatObserver(); if (tempUser && !tempUser.communicationLanguage && $locale) diff --git a/src/routes/account/+page.svelte b/src/routes/account/+page.svelte index fcb1d0b0..f17458fc 100644 --- a/src/routes/account/+page.svelte +++ b/src/routes/account/+page.svelte @@ -5,7 +5,7 @@ import { updateMailPreferences } from '@/lib/api/user'; import { resendAccountVerification } from '@/lib/api/auth'; import { changeListedStatus } from '$lib/api/garden'; - import { getUser, user } from '@/lib/stores/auth'; + import { user } from '@/lib/stores/auth'; import { updatingMailPreferences } from '$lib/stores/user'; import { Avatar, Icon, Button, LabeledCheckbox } from '$lib/components/UI'; import { flagIcon, emailIcon } from '$lib/images/icons'; @@ -13,6 +13,7 @@ import routes from '$lib/routes'; import { SUPPORT_EMAIL } from '$lib/constants'; import { createCustomerPortalSession } from '@/lib/api/functions'; + import ReloadSuggestion from '@/lib/components/ReloadSuggestion.svelte'; if (!$user) { goto(routes.SIGN_IN); @@ -121,6 +122,7 @@ {:else}{$_('account.verify.sent')}
{/if} +