Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session Cookie with knex.js #595

Closed
codelover2k opened this issue Aug 20, 2020 · 4 comments
Closed

Session Cookie with knex.js #595

codelover2k opened this issue Aug 20, 2020 · 4 comments
Labels
incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. question Ask how to do something or how something works stale Did not receive any activity for 60 days

Comments

@codelover2k
Copy link

codelover2k commented Aug 20, 2020

I am trying to switch to Next.js and before that I used Express.

For authentication I used express-session and connect-session-knex.
The great thing about connect-session-knex is that it creates the data table for you and if something changes or if you delete that table, it just creates a fresh one for you.

Furthermore it automatically deletes sessions from the database if they are not valid anymore, so you can set the time how many times the database should be checked for dead sessions.
In my case these modules check the database every 60 minutes and deletes sessions to keep the table small and fast as possible.

I would like to know if you have these features also in next-auth?

  • Will the required data table be created automatically and also updated if needed? (for example if a new version is there)

  • can you also use knex.js? (if yes an example would be nice)

  • does it also check the database and clean dead sessions if it find any?

Would be great if someone could help me with that :)

@codelover2k codelover2k added the question Ask how to do something or how something works label Aug 20, 2020
@iaincollins iaincollins added the incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. label Aug 24, 2020
@iaincollins
Copy link
Member

  • Will the required data table be created automatically and also updated if needed? (for example if a new version is there)

If the synchronize option is set to true in the database options NextAuth.js will automatically create or update any tables needed (this is handled by TypeORM), however enabling this option is not currently recommended in production as it does not actually perform a migration and could lead to data loss between releases.

The synchronize option is intended to make it easier to get started, but SQL schema changes need to be handled manually currently - with this in mind, we generally avoid making changes to the schema (until we have improved support for handling migrations). There are some changes I would like to make that require an SQL schema change, but I'm currently not focusing on them for that reason. I anticipate we will have migration support at some point, for either TypeORM, Prisma or both.

Note: We also maintain SQL schemas (e.g. MySQL schema, Postgres schema) for the current version.

  • can you also use knex.js? (if yes an example would be nice)

NextAuth.js ships with adapters that use TypeORM and Prisma and supports MySQL, Postgres, Microsoft SQL Server, MongoDB (and other databases compatible with them). To use another database or ORM you can create a custom adapter.

You can also pass a database connection string to NextAuth.js and let it handle it's own connection without worrying about it, and connect to the database from your own application using whatever method you want.

  • does it also check the database and clean dead sessions if it find any?

Not currently. I expect this will be something we will add to the default database adapter fairly soon.

@codelover2k
Copy link
Author

thanks for response Iain, I will try it out!
it would be great to have an example of the session cookie based strategy, because in many cases where you need authentication, a session based cookie is recommended and better than JWTs.

@stale
Copy link

stale bot commented Dec 5, 2020

Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep ot open. Thanks!

@stale stale bot added the wontfix This will not be worked on label Dec 5, 2020
@balazsorban44 balazsorban44 added stale Did not receive any activity for 60 days and removed wontfix This will not be worked on labels Dec 5, 2020
@stale
Copy link

stale bot commented Dec 12, 2020

Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks!

@stale stale bot closed this as completed Dec 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incomplete Insufficient reproduction. Without more info, we won't take further actions/provide help. question Ask how to do something or how something works stale Did not receive any activity for 60 days
Projects
None yet
Development

No branches or pull requests

3 participants