implemented some login stuff.

This commit is contained in:
sockenklaus
2023-07-04 01:08:21 +02:00
parent 7a2b63ee07
commit f98fc36e51
11 changed files with 124 additions and 40 deletions

View File

@@ -15,6 +15,7 @@
import Logger from '@ioc:Adonis/Core/Logger'
import HttpExceptionHandler from '@ioc:Adonis/Core/HttpExceptionHandler'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class ExceptionHandler extends HttpExceptionHandler {
protected statusPages = {
@@ -26,4 +27,21 @@ export default class ExceptionHandler extends HttpExceptionHandler {
constructor() {
super(Logger)
}
public async handle(error: any, ctx: HttpContextContract) {
const { session, response } = ctx;
/**
* Handle failed authentication attempt
*/
if (['E_INVALID_AUTH_PASSWORD', 'E_INVALID_AUTH_UID'].includes(error.code)) {
session.flash('errors', { login: error.message });
return response.redirect().back();
}
/**
* Forward rest of the exceptions to the parent class
*/
return super.handle(error, ctx);
}
}