Skip to content

Commit

Permalink
Merge pull request #402 from reedu-reengineering-education/fix/passwo…
Browse files Browse the repository at this point in the history
…rdErrors

added some error messages and fix some transl.
  • Loading branch information
Thiemann96 authored Dec 11, 2024
2 parents de043a7 + e4d1849 commit 4096e34
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 42 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"react-twitter-embed": "^4.0.4",
"react-youtube": "^10.1.0",
"resend": "^2.1.0",
"sharp": "^0.33.5",
"slugify": "^1.6.5",
"spotify-embed": "^1.5.0",
"superjson": "^1.12.2",
Expand Down
11 changes: 0 additions & 11 deletions src/app/[lng]/(auth)/passwordRequest/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ export default async function RequestPasswordPage({
</p>
</div>
<UserAuthRequestPassword />
{/* <h1 className="text-center">Noch keinen Account?</h1>
<p className="px-8 text-center text-sm text-slate-600">
{t('disclaimerRegister')}{' '}
<Link className="hover:text-brand underline" href="/terms">
{t('TOS')}
</Link>{' '}
{t('and')}{' '}
<Link className="hover:text-brand underline" href="/privacy">
{t('PP')}
</Link>
</p> */}
</div>
</div>
)
Expand Down
6 changes: 4 additions & 2 deletions src/app/i18n/locales/de/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"enter_email_and_password_for_signin": "Gib deine E-Mail-Adresse und dein Passwort ein, um dich",
"password_login_hint": "Wenn Sie das Passwortverfahren aktiviert haben, können Sie sich auch damit einloggen.",
"password_login_link": "Hier klicken, um zum Passwort-Login zu gelangen.",
"enable_password_login": "Wenn du das Passwortverfahren aktivieren möchtest, folge diesem ",
"enable_password_login": "Wenn du das Passwortverfahren aktivieren möchtest, folge diesem",
"link": "Link ",
"enable_password_login_end": "und folge den Anweisungen.",
"enter_email_for_password_request": "Gib deine E-Mail-Adresse ein, um ein Passwort anzufragen",
"password_request": "Passwort anfragen"
"password_request": "Passwort anfragen",
"wrongPassword": "Falsches Passwort oder E-Mail-Adresse",
"unexpectedError": "Unerwarteter Fehler"
}
4 changes: 3 additions & 1 deletion src/app/i18n/locales/en/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"link": "link ",
"enable_password_login_end": "and follow the instructions.",
"enter_email_for_password_request": " Enter your email address to request a password",
"password_request": "Request password"
"password_request": "Request password",
"wrongPassword": "Wrong password or email address",
"unexpectedError": "Unexpected error"
}
4 changes: 3 additions & 1 deletion src/app/i18n/locales/es/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"link": "Link ",
"enable_password_login_end": "y sigue las instrucciones.",
"enter_email_for_password_request": "Ingresa tu dirección de correo electrónico para solicitar una contraseña",
"password_request": "Solicitar contraseña"
"password_request": "Solicitar contraseña",
"wrongPassword": "Contraseña o dirección de correo electrónico incorrecta",
"unexpectedError": "Error inesperado"
}
4 changes: 3 additions & 1 deletion src/app/i18n/locales/fr/login.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"link": "link ",
"enable_password_login_end": "et suivez les instructions.",
"enter_email_for_password_request": " Entrez votre adresse e-mail pour demander un mot de passe",
"password_request": "Demander un mot de passe"
"password_request": "Demander un mot de passe",
"wrongPassword": "Mot de passe ou adresse e-mail incorrecte",
"unexpectedError": "Erreur inattendue"
}
45 changes: 31 additions & 14 deletions src/components/Auth/UserAuthPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,42 @@ export function UserAuthPassword({
const handleSubmit = async (e: FormEvent) => {
e.preventDefault()

const result = await signIn('credentials', {
email,
password,
redirect: false, // Verhindert automatische Weiterleitung
})
if (!result?.ok) {
try {
const result = await signIn('credentials', {
email,
password,
redirect: false, // Verhindert automatische Weiterleitung
})

if (!result || !result.ok) {
const errorMessage =
result?.status === 401
? t('wrongPassword') // Spezifische Meldung für 401
: result?.error || t('signin_fail') // Standard-Fehlermeldung oder Nachricht aus der HTTP-Antwort

return toast({
title: t('something_wrong'),
message: errorMessage,
type: 'error',
})
}

// Erfolg: Weiterleitung
router.push('/storylab')
return toast({
title: t('loginSuccess'),
message: t('loginSuccessText'),
type: 'success',
})
} catch (error: any) {
// Fallback für unerwartete Fehler
const errorMessage = error.response?.data?.message || t('unexpectedError')
return toast({
title: t('something_wrong'),
message: t('signin_fail'),
message: errorMessage,
type: 'error',
})
}

router.push('/storylab')
return toast({
title: t('loginSuccess'),
message: t('loginSuccessText'),
type: 'success',
})
}

return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/Auth/UserAuthRequestPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export function UserAuthRequestPassword({
})

if (result.status !== 200) {
const response = await result.json()
return toast({
title: t('something_wrong'),
message: t('signin_fail'),
message: response.message,
type: 'error',
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Elements/ContentCreates/EmbedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export function EmbedContent({
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>Quelle </InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
onChange={e => handleFileSource(e)}
value={fileSource}
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/Elements/ContentCreates/MediaContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export function MediaContent({ setFile }: MediaContentEditProps) {
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>Quelle </InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Elements/ContentEdits/EmbedContentEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export function EmbedContentEdit({
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>Quelle </InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
onChange={e => handleFileSource(e)}
value={fileSource}
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/Elements/ContentEdits/MediaContentEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export function MediaContent({
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>Quelle </InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
Expand Down
3 changes: 1 addition & 2 deletions src/components/Studio/ContentTypes/MediaContentType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,9 @@ export function MediaContentEdit({
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>{t('source')}</InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
label={t('source')}
onChange={e => handleFileSource(e)}
value={fileSource}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ export function EmbedContentEdit({
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>Quelle </InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
onChange={e => handleFileSource(e)}
value={fileSource}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export function MediaContentEdit({
</div>
{/* input field to give a source */}
<div className="flex items-center gap-2">
<InputLabel>Quelle </InputLabel>
<Input
className="bg-slate-50"
label="Quelle"
Expand Down
Loading

0 comments on commit 4096e34

Please sign in to comment.