Unique validate error on new user that doesnt exists #3980
Unanswered
AngelGC1981
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I build a test app that needs a sign up and login, in my local server before use the build --production everything works well but after the deploy to the hosting server both registration and login do not work, flashmessages always catch the unique error of the validator and the tables of the database are empty
This is my code after the .ts to .js compile :
class AuthController {
async newuser({ request, auth, response }) {
const validationSchema = Validator_1.schema.create({
nombre_u: Validator_1.schema.string({ trim: true }, [
Validator_1.rules.unique({ table: "users", column: "nombre_u" }),
Validator_1.rules.maxLength(15),
]),
email: Validator_1.schema.string({ trim: true }, [
Validator_1.rules.email(),
Validator_1.rules.unique({ table: "users", column: "email" }),
]),
password: Validator_1.schema.string({ trim: true }),
});
const userDetails = await request.validate({
schema: validationSchema,
messages: {
'nombre_u.required': 'Introduce un nombre de usuario válido',
'nombre_u.unique': 'Nombre de usuario ya está en uso',
'nombre_u.maxLength': 'No puede exceder de 15 caracteres',
'email.required': 'Introduce un e-mail válido',
'email.email': 'Introduce un e-mail válido',
'email.unique': 'e-mail en uso',
'email.maxLength': 'No puede exceder de 200 caracteres',
'password.required': 'Introduce un password válido'
}
});
const user = await User_1.default.create(userDetails);
await auth.login(user);
return response.redirect('/control');
}
async login({ request, auth, session, response }) {
const { email, password } = request.all();
try {
await auth.attempt(email, password);
return response.redirect('/control');
}
catch (error) {
session.flash('notification', 'No podemos verificar tus credenciales, Email o contraseña incorrectos');
//session.flashMessages.all();
return response.redirect('back');
}
}
I tried to quit the unique validation rule in both keys but then the application just give and error 500
I am desperate because the script does not return errors apart from the unique error and the connection to the database works becouse I have made the migrations and they have worked well.
Please I will be grateful if anyone can help me on this becouse i am new learning adonis and i do not know hot to fix it or at least know how to get the real error
Thank you
Beta Was this translation helpful? Give feedback.
All reactions