Skip to content

Commit

Permalink
fix: reset password form errors are now being shown
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaspalma committed Jan 26, 2025
1 parent 4155333 commit 64cd1f8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions website/app/controllers/authentication_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ export default class AuthenticationController {
return response.redirect().toRoute('page:auth.forgot-password.sent')
}

async callbackForForgotPassword({ request, inertia }: HttpContext) {
async callbackForForgotPassword({ request, response, session }: HttpContext) {
const { email } = await request.validateUsing(emailVerificationCallbackValidator)

return inertia.render('auth/forgot-password/reset', { email })
session.flash('forgot-password-email', email)
return response.redirect().toRoute('pages:auth.forgot-password.change')
}

async showForgotPasswordPage({ inertia, session }: HttpContext) {
return inertia.render('auth/forgot-password/reset', { email: session.flashMessages.get('forgot-password-email') })
}

async changePassword({ request, response }: HttpContext) {
Expand Down
1 change: 0 additions & 1 deletion website/inertia/pages/auth/forgot-password/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default function ForgotPasswor() {

const { data, setData, errors, post } = useForm({
email: '',
password: '',
})

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
Expand Down
4 changes: 2 additions & 2 deletions website/inertia/pages/auth/forgot-password/reset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function ForgotPasswor() {
const page = usePage()
const oauthError = useError('oauth')

const { data, setData, post } = useForm({
const { data, setData, errors, post } = useForm({
email: String(page.props.email),
password: '',
password_confirmation: '',
Expand Down Expand Up @@ -58,6 +58,7 @@ export default function ForgotPasswor() {
onChange={(e) => setData('password_confirmation', e.target.value)}
required
/>
{errors.password && <p className="text-sm text-red-600">{errors.password}</p>}
</div>
<div className="flex flex-col gap-4 ">
<Button type="submit" className="w-full bg-enei-blue">
Expand All @@ -66,7 +67,6 @@ export default function ForgotPasswor() {
</div>
</div>
</form>
{oauthError && <p className="text-sm text-red-600 text-center mt-4">{oauthError}</p>}
</CardContent>
</Card>
</CardLayout>
Expand Down
2 changes: 1 addition & 1 deletion website/inertia/pages/auth/forgot-password/success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CardLayout from '~/layouts/card'

export default function EmailVerification() {
return (
<BaseLayout title="E-mail confirmado">
<BaseLayout title="Palavra-passe alterada">
<CardLayout>
<Card>
<CardHeader>
Expand Down
4 changes: 4 additions & 0 deletions website/start/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ router
.as('actions:auth.forgot-password.callback')
.middleware([middleware.verifyUrlSignature(), middleware.automaticSubmit()])

router
.get('/password/forgot/reset', [AuthenticationController, 'showForgotPasswordPage'])
.as('pages:auth.forgot-password.change')

router
.post('/password/forgot/reset', [AuthenticationController, 'changePassword'])
.as('actions:auth.forgot-password.change')
Expand Down

0 comments on commit 64cd1f8

Please sign in to comment.