mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 22:01:09 +02:00
✨ feat(auth): add resend verification email to all login pages
Add ability to resend verification email when login fails with "Email not verified" error. Implemented across all 14 apps using Mana Core Auth. Changes: - Add POST /api/v1/auth/resend-verification endpoint to mana-core-auth - Add resendVerificationEmail method to shared-auth client - Update LoginPage component with resend UI and translations - Add resendVerificationEmail to all app auth stores - Add translations for de, en, fr, es, it - Add PlantaLogo to shared-branding - Migrate planta login to shared LoginPage component
This commit is contained in:
parent
f911243bf0
commit
0c150df0f1
45 changed files with 691 additions and 110 deletions
|
|
@ -30,6 +30,10 @@
|
|||
signInSuccess: string;
|
||||
googleSignInSuccess: string;
|
||||
emailVerified?: string;
|
||||
emailNotVerified?: string;
|
||||
resendVerification?: string;
|
||||
resendingVerification?: string;
|
||||
verificationEmailSent?: string;
|
||||
}
|
||||
|
||||
const defaultTranslations: LoginTranslations = {
|
||||
|
|
@ -56,6 +60,10 @@
|
|||
signInSuccess: 'Successfully signed in. Redirecting...',
|
||||
googleSignInSuccess: 'Successfully signed in with Google. Redirecting...',
|
||||
emailVerified: 'Email successfully verified! Please sign in.',
|
||||
emailNotVerified: 'Email not verified.',
|
||||
resendVerification: 'Resend verification email',
|
||||
resendingVerification: 'Sending...',
|
||||
verificationEmailSent: 'Verification email sent! Please check your inbox.',
|
||||
};
|
||||
|
||||
interface Props {
|
||||
|
|
@ -65,6 +73,7 @@
|
|||
onSignIn: (email: string, password: string) => Promise<AuthResult>;
|
||||
onSignInWithGoogle?: (idToken: string) => Promise<AuthResult>;
|
||||
onSignInWithApple?: (identityToken: string) => Promise<AuthResult>;
|
||||
onResendVerification?: (email: string) => Promise<AuthResult>;
|
||||
goto: (path: string) => void;
|
||||
enableGoogle?: boolean;
|
||||
enableApple?: boolean;
|
||||
|
|
@ -91,6 +100,7 @@
|
|||
onSignIn,
|
||||
onSignInWithGoogle,
|
||||
onSignInWithApple,
|
||||
onResendVerification,
|
||||
goto,
|
||||
enableGoogle = false,
|
||||
enableApple = false,
|
||||
|
|
@ -122,6 +132,9 @@
|
|||
let passwordInput: HTMLInputElement;
|
||||
let successAnnouncement = $state('');
|
||||
let showVerifiedBanner = $state(verified);
|
||||
let showEmailNotVerified = $state(false);
|
||||
let resendingVerification = $state(false);
|
||||
let verificationEmailSent = $state(false);
|
||||
|
||||
// Theme state - can be toggled manually, defaults to system preference
|
||||
let userThemePreference = $state<'light' | 'dark' | null>(null);
|
||||
|
|
@ -192,6 +205,8 @@
|
|||
async function handleLogin() {
|
||||
loading = true;
|
||||
clearError();
|
||||
showEmailNotVerified = false;
|
||||
verificationEmailSent = false;
|
||||
|
||||
if (!email) {
|
||||
setError(t.emailRequired, 'email');
|
||||
|
|
@ -216,6 +231,26 @@
|
|||
showSuccess = true;
|
||||
successAnnouncement = t.signInSuccess;
|
||||
setTimeout(() => goto(successRedirect), 600);
|
||||
} else if (result.error === 'EMAIL_NOT_VERIFIED') {
|
||||
showEmailNotVerified = true;
|
||||
setError(t.emailNotVerified || 'Email not verified.', 'general');
|
||||
} else {
|
||||
setError(result.error || t.signInFailed, 'general');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResendVerification() {
|
||||
if (!onResendVerification || !email || resendingVerification) return;
|
||||
|
||||
resendingVerification = true;
|
||||
clearError();
|
||||
|
||||
const result = await onResendVerification(email);
|
||||
resendingVerification = false;
|
||||
|
||||
if (result.success) {
|
||||
verificationEmailSent = true;
|
||||
showEmailNotVerified = false;
|
||||
} else {
|
||||
setError(result.error || t.signInFailed, 'general');
|
||||
}
|
||||
|
|
@ -333,10 +368,38 @@
|
|||
<p class="form-subtitle">{t.subtitle}</p>
|
||||
</div>
|
||||
|
||||
{#if verificationEmailSent}
|
||||
<div class="verified-banner" role="status" aria-live="polite">
|
||||
<Check size={18} class="text-green-500 shrink-0" />
|
||||
<p>{t.verificationEmailSent}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="verified-banner-close"
|
||||
onclick={() => (verificationEmailSent = false)}
|
||||
aria-label="Close"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="error-message" id="form-error" role="alert" aria-live="assertive">
|
||||
<Warning size={18} class="text-red-500 shrink-0" />
|
||||
<p>{error}</p>
|
||||
<div class="error-content">
|
||||
<p>{error}</p>
|
||||
{#if showEmailNotVerified && onResendVerification}
|
||||
<button
|
||||
type="button"
|
||||
class="resend-link"
|
||||
onclick={handleResendVerification}
|
||||
disabled={resendingVerification}
|
||||
style:color={primaryColor}
|
||||
>
|
||||
{resendingVerification ? t.resendingVerification : t.resendVerification}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
|
@ -679,7 +742,7 @@
|
|||
|
||||
.error-message {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
|
|
@ -690,6 +753,32 @@
|
|||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.error-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.resend-link {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
font-size: 0.875rem;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.resend-link:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.resend-link:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ const DEFAULT_ENDPOINTS: AuthEndpoints = {
|
|||
validate: '/api/v1/auth/validate',
|
||||
forgotPassword: '/api/v1/auth/forgot-password',
|
||||
resetPassword: '/api/v1/auth/reset-password',
|
||||
resendVerification: '/api/v1/auth/resend-verification',
|
||||
googleSignIn: '/api/v1/auth/google-signin',
|
||||
appleSignIn: '/api/v1/auth/apple-signin',
|
||||
credits: '/api/v1/credits/balance',
|
||||
|
|
@ -247,6 +248,37 @@ export function createAuthService(config: AuthServiceConfig) {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resend verification email
|
||||
* @param email - User's email address
|
||||
* @param sourceAppUrl - Optional URL to redirect after verification (current app origin)
|
||||
*/
|
||||
async resendVerificationEmail(email: string, sourceAppUrl?: string): Promise<AuthResult> {
|
||||
try {
|
||||
const response = await fetch(`${baseUrl}${endpoints.resendVerification}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, sourceAppUrl }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
return {
|
||||
success: false,
|
||||
error: errorData.message || 'Failed to resend verification email',
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error resending verification email:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Refresh the authentication tokens
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ export interface AuthEndpoints {
|
|||
validate: string;
|
||||
forgotPassword: string;
|
||||
resetPassword: string;
|
||||
resendVerification: string;
|
||||
googleSignIn: string;
|
||||
appleSignIn: string;
|
||||
credits: string;
|
||||
|
|
|
|||
|
|
@ -246,6 +246,19 @@ export const APP_BRANDING: Record<AppId, AppBranding> = {
|
|||
logoStroke: true,
|
||||
logoStrokeWidth: 1.5,
|
||||
},
|
||||
planta: {
|
||||
id: 'planta',
|
||||
name: 'Planta',
|
||||
tagline: 'Plant Care Assistant',
|
||||
primaryColor: '#22c55e',
|
||||
secondaryColor: '#4ade80',
|
||||
// Plant/leaf icon
|
||||
logoPath:
|
||||
'M12 21a9.004 9.004 0 008.716-6.747M12 21a9.004 9.004 0 01-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 017.843 4.582M12 3a8.997 8.997 0 00-7.843 4.582m15.686 0A11.953 11.953 0 0112 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0121 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0112 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 013 12c0-1.605.42-3.113 1.157-4.418',
|
||||
logoViewBox: '0 0 24 24',
|
||||
logoStroke: true,
|
||||
logoStrokeWidth: 1.5,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ export {
|
|||
ClockLogo,
|
||||
QuestionsLogo,
|
||||
SkillTreeLogo,
|
||||
PlantaLogo,
|
||||
} from './logos';
|
||||
|
||||
// Configuration
|
||||
|
|
|
|||
13
packages/shared-branding/src/logos/PlantaLogo.svelte
Normal file
13
packages/shared-branding/src/logos/PlantaLogo.svelte
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<script lang="ts">
|
||||
import AppLogo from '../AppLogo.svelte';
|
||||
|
||||
interface Props {
|
||||
size?: number;
|
||||
color?: string;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
let { size = 55, color, class: className = '' }: Props = $props();
|
||||
</script>
|
||||
|
||||
<AppLogo app="planta" {size} {color} class={className} />
|
||||
|
|
@ -20,3 +20,4 @@ export { default as InventoryLogo } from './InventoryLogo.svelte';
|
|||
export { default as ClockLogo } from './ClockLogo.svelte';
|
||||
export { default as QuestionsLogo } from './QuestionsLogo.svelte';
|
||||
export { default as SkillTreeLogo } from './SkillTreeLogo.svelte';
|
||||
export { default as PlantaLogo } from './PlantaLogo.svelte';
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ export type AppId =
|
|||
| 'moodlit'
|
||||
| 'inventory'
|
||||
| 'questions'
|
||||
| 'skilltree';
|
||||
| 'skilltree'
|
||||
| 'planta';
|
||||
|
||||
/**
|
||||
* App branding configuration
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@
|
|||
"signInFailed": "Anmeldung fehlgeschlagen",
|
||||
"googleSignInFailed": "Google-Anmeldung fehlgeschlagen",
|
||||
"signInSuccess": "Erfolgreich angemeldet. Weiterleitung...",
|
||||
"googleSignInSuccess": "Erfolgreich mit Google angemeldet. Weiterleitung..."
|
||||
"googleSignInSuccess": "Erfolgreich mit Google angemeldet. Weiterleitung...",
|
||||
"emailVerified": "E-Mail erfolgreich bestätigt! Bitte melde dich an.",
|
||||
"emailNotVerified": "E-Mail nicht bestätigt.",
|
||||
"resendVerification": "Bestätigungs-E-Mail erneut senden",
|
||||
"resendingVerification": "Wird gesendet...",
|
||||
"verificationEmailSent": "Bestätigungs-E-Mail wurde gesendet! Bitte überprüfe deinen Posteingang."
|
||||
},
|
||||
"register": {
|
||||
"title": "Konto erstellen",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@
|
|||
"signInFailed": "Sign in failed",
|
||||
"googleSignInFailed": "Google sign in failed",
|
||||
"signInSuccess": "Successfully signed in. Redirecting...",
|
||||
"googleSignInSuccess": "Successfully signed in with Google. Redirecting..."
|
||||
"googleSignInSuccess": "Successfully signed in with Google. Redirecting...",
|
||||
"emailVerified": "Email successfully verified! Please sign in.",
|
||||
"emailNotVerified": "Email not verified.",
|
||||
"resendVerification": "Resend verification email",
|
||||
"resendingVerification": "Sending...",
|
||||
"verificationEmailSent": "Verification email sent! Please check your inbox."
|
||||
},
|
||||
"register": {
|
||||
"title": "Create Account",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@
|
|||
"signInFailed": "Error al iniciar sesión",
|
||||
"googleSignInFailed": "Error al iniciar sesión con Google",
|
||||
"signInSuccess": "Sesión iniciada correctamente. Redirigiendo...",
|
||||
"googleSignInSuccess": "Sesión iniciada con Google correctamente. Redirigiendo..."
|
||||
"googleSignInSuccess": "Sesión iniciada con Google correctamente. Redirigiendo...",
|
||||
"emailVerified": "¡Correo verificado exitosamente! Por favor inicia sesión.",
|
||||
"emailNotVerified": "Correo no verificado.",
|
||||
"resendVerification": "Reenviar correo de verificación",
|
||||
"resendingVerification": "Enviando...",
|
||||
"verificationEmailSent": "¡Correo de verificación enviado! Por favor revisa tu bandeja de entrada."
|
||||
},
|
||||
"register": {
|
||||
"title": "Crear Cuenta",
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@
|
|||
"signInFailed": "Échec de la connexion",
|
||||
"googleSignInFailed": "Échec de la connexion Google",
|
||||
"signInSuccess": "Connexion réussie. Redirection...",
|
||||
"googleSignInSuccess": "Connexion Google réussie. Redirection..."
|
||||
"googleSignInSuccess": "Connexion Google réussie. Redirection...",
|
||||
"emailVerified": "Email vérifié avec succès ! Veuillez vous connecter.",
|
||||
"emailNotVerified": "Email non vérifié.",
|
||||
"resendVerification": "Renvoyer l'email de vérification",
|
||||
"resendingVerification": "Envoi en cours...",
|
||||
"verificationEmailSent": "Email de vérification envoyé ! Veuillez vérifier votre boîte de réception."
|
||||
},
|
||||
"register": {
|
||||
"title": "Créer un compte",
|
||||
|
|
|
|||
|
|
@ -37,6 +37,11 @@ export interface AuthTranslations {
|
|||
googleSignInFailed: string;
|
||||
signInSuccess: string;
|
||||
googleSignInSuccess: string;
|
||||
emailVerified?: string;
|
||||
emailNotVerified?: string;
|
||||
resendVerification?: string;
|
||||
resendingVerification?: string;
|
||||
verificationEmailSent?: string;
|
||||
};
|
||||
register: {
|
||||
title: string;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,12 @@
|
|||
"signInFailed": "Accesso fallito",
|
||||
"googleSignInFailed": "Accesso con Google fallito",
|
||||
"signInSuccess": "Accesso effettuato. Reindirizzamento...",
|
||||
"googleSignInSuccess": "Accesso con Google effettuato. Reindirizzamento..."
|
||||
"googleSignInSuccess": "Accesso con Google effettuato. Reindirizzamento...",
|
||||
"emailVerified": "Email verificata con successo! Effettua l'accesso.",
|
||||
"emailNotVerified": "Email non verificata.",
|
||||
"resendVerification": "Invia di nuovo l'email di verifica",
|
||||
"resendingVerification": "Invio in corso...",
|
||||
"verificationEmailSent": "Email di verifica inviata! Controlla la tua casella di posta."
|
||||
},
|
||||
"register": {
|
||||
"title": "Crea Account",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue