Closed Pacheco95 closed 4 years ago
I tried to switch the default database to be the sqlite and now this error is happening
[1600116267100] INFO (backend-ts/44480 on redacted): started server on 0.0.0.0:3333
[1600116270904] ERROR (backend-ts/44480 on redacted): Cannot find module 'phc-argon2'
Require stack:
- redacted/backend-ts/node_modules/@adonisjs/hash/build/src/Drivers/Argon.js
- redacted/backend-ts/node_modules/@adonisjs/hash/build/src/Hash/index.js
- redacted/backend-ts/node_modules/@adonisjs/hash/build/providers/HashProvider.js
- redacted/backend-ts/node_modules/@poppinss/utils/build/src/esmRequire.js
- redacted/backend-ts/node_modules/@poppinss/utils/build/index.js
- redacted/backend-ts/node_modules/@adonisjs/core/build/src/Ignitor/Bootstrapper/index.js
- redacted/backend-ts/node_modules/@adonisjs/core/build/src/Ignitor/Ace/AppCommands.js
- redacted/backend-ts/node_modules/@adonisjs/core/build/src/Ignitor/Ace/index.js
- redacted/backend-ts/node_modules/@adonisjs/core/build/src/Ignitor/index.js
- redacted/backend-ts/build/server.js
Installing it manually solved the problem and the users are being created but when trying to await auth.login(user)
it is returning this error
{
"message": "Cannot read property 'put' of undefined",
"stack": "TypeError: Cannot read property 'put' of undefined\n at SessionGuard.setSession (/home/michael/repositories/cataki-dashboard/backend-ts/node_modules/@adonisjs/auth/build/src/Guards/Session/index.js:46:26)\n at SessionGuard.login (/home/michael/repositories/cataki-dashboard/backend-ts/node_modules/@adonisjs/auth/build/src/Guards/Session/index.js:197:14)\n at Auth.login (/home/michael/repositories/cataki-dashboard/backend-ts/node_modules/@adonisjs/auth/build/src/Auth/index.js:114:27)\n at AuthController.register (/home/michael/repositories/cataki-dashboard/backend-ts/app/Controllers/Http/AuthController.ts:33:16)\n at Object.PreCompiler.runRouteHandler [as fn] (/home/michael/repositories/cataki-dashboard/backend-ts/node_modules/@adonisjs/http-server/build/src/Server/PreCompiler/index.js:46:31)\n at Server.handle (/home/michael/repositories/cataki-dashboard/backend-ts/node_modules/@adonisjs/http-server/build/src/Server/index.js:138:13)"
}
I created a naked project to reproduce this issue https://github.com/Pacheco95/adonis-auth-test
I see there are some mis-conceptions in the way you expect things to work.
As an additional note, I also had problems with migrations even with presence of static get connection() inside the User model
Migrations have nothing to do with the models. Migrations automates the process of creating and managing the database schema. Whereas models are used to query them. They are two dis-jointed pieces.
Regarding email validation. The validator doesn't use models, it makes a direct query to the database. You can define a custom connection to the unique
rule.
rules.unique({
connection: 'sqlite',
})
Now that we have mis-conceptions cleared. We can look into the migrations targeting different connections. I recommend keeping the migrations of different connections inside different directories, especially when each connection has different migrations all together.
Inside the config/database.ts
file. Define the migration paths for your defined connections.
sqlite: {
client: 'sqlite',
connection: {},
migrations: {
paths: ['./database/migrations/sqlite']
},
}
Now the make:migration
and migration:run
commands will use the paths defined inside the config file over the default path.
Thanks for clarification about models and migrations. But what about this error? https://github.com/adonisjs/auth/issues/148#issuecomment-692313295. Even doing your tips I still cannot login users.
Since you are using the Session driver you need to ensure that the session module is installed in your application.
Oh man! You saved my day. Following the docs in https://preview.adonisjs.com/guides/auth/web-guard/#when-to-use-the-web-guard I just ran npm i @adonisjs/session
and npm installed ^1.0.29
version. I did not entered the configuration page and ran the invoke
command. Now its everything working. Thank you again and sorry about my negligence
No worries. We can trying to improve error reporting in certain cases. Will surely look into it :)
I'm setting up authentication to a new Adonis 5 project and followed the doc instructions
The key problem is that I'm using two connection databases. One for an external DB connection (default) and one for app users related stuff. When I tried to register a new user with
AuthController.register
it has returned this error:which is trying to connect with the wrong database. I could not find a solution to this problem in the docs, so I searched in previous Adonis versions and found this one https://forum.adonisjs.com/t/changing-database-connection-in-model/2583 but without any success.
As an additional note, I also had problems with migrations even with presence of
static get connection()
inside the User model, but I have noticed thatnode ace migration:run
accepts a flag-c
which selects the correct connection to use and it seems to work well. It should be nice to have the possibility to setup the connection to migrations.Package version
5.0.0-preview-rc-1.12
Node.js and npm version
Node: v12.18.3 Npm: 6.14.8
Sample Code (to reproduce the issue)