-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
fix: check convertSessionIdToMongoObjectId
before using idProvider
#1205
fix: check convertSessionIdToMongoObjectId
before using idProvider
#1205
Conversation
🦋 Changeset detectedLatest commit: 4ae3653 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
convertSessionIdToMongoObjectId
before using idProvider
convertSessionIdToMongoObjectId
before using idProvider
convertSessionIdToMongoObjectId
before using idProvider
Codecov Report
@@ Coverage Diff @@
## master #1205 +/- ##
=======================================
Coverage 95.28% 95.29%
=======================================
Files 106 106
Lines 2377 2381 +4
Branches 473 492 +19
=======================================
+ Hits 2265 2269 +4
+ Misses 107 103 -4
- Partials 5 9 +4
Continue to review full report at Codecov.
|
Thanks for the fix! |
What are your thoughts? |
To avoid a maximum the breaking changes and impact the users when they will upgrade to the new version option 1 seems good :)
I am just not sure about this, this would mean that idProvider is actually not used if the value is false right? That can be really confusing. |
Yeah... Hm... I think they're pretty even options, but I think your option of just including an Alternatively, we could log a developer warning in the console when in development mode under the following conditions:
This would let the developer know they have things misconfigured. |
The warning approach sounds like a good idea 👍 |
The approach I'm thinking about will be very simple:
if (typeof this.options.idSessionProvider === 'function' && this.options.convertSessionIdToMongoObjectId) {
console.warn(`You have set both "idSessionProvider" and "convertSessionIdToMongoObjectId = false" which will cause your "idSessionProvider" to be ignored.
In order to fix this warning change "convertSessionIdToMongoObjectId" to "true" or remove your "idSessionProvider" from the configuration.
`);
}
What do you think of that approach, anything I'm missing? It seems like I can contain all those changes within this PR, but let me know if I need to open a separate one for docs or for MongoDB Password (same changes). Thanks for any feedback! (Addressed in 3c718c1) |
I also couldn't help but notice that the Mongo Options contains configuration that assumes you will use Accounts Password as your strategy, see |
Change provider option name to be more explicit
I was trying the change and noticed something that was possible before but not possible with this change: const userStorage = new MongoDbDriver(mongoose.connection, {
convertUserIdToMongoObjectId: true,
// Date.now() can be replaced by any value here
idProvider: () => new mongoose.Types.ObjectId(Date.now()),
}); |
@pradel I see that the "Test Packages" Github workflow is failing. Since this is a breaking change, I feel like that is expected, but could use your guidance on how to proceed. |
The tests failing are coming from here, https://github.com/accounts-js/accounts/blob/master/packages/database-tests/src/index.ts |
@pradel Thanks! So it looks like I need to add the new There's other code that uses that dependency injection for running the tests, but it's for Redis. |
Yes, you might have to edit the mongo package to pass down the options for the tests to run properly :) |
@pradel tests are passing. Let me know once you've tested some things. I had to add a type definition to the Also, please refer to a previous question about the strategy for updating the docs. If the latter is preferred, and you can offer clear enough directions on how I can find all combinations I can take care of this now. Otherwise, it might be good for you or someone else to tackle that in a separate PR. |
I get this error when I try to run all tests: ~/Code/forks/accounts$ pnpm run testonly
> @0.22.0 testonly /home/kevin/Code/forks/accounts
> lerna run testonly
lerna notice cli v4.0.0
lerna info Executing command in 23 packages: "pnpm run testonly"
lerna ERR! pnpm run testonly exited 1 in '@accounts/oauth-twitter'
lerna ERR! pnpm run testonly stdout:
> @accounts/oauth-twitter@0.32.1 testonly /home/kevin/Code/forks/accounts/packages/oauth-twitter
> jest
ELIFECYCLE Command failed with exit code 1.
lerna ERR! pnpm run testonly stderr:
FAIL __tests__/index.ts
● Test suite failed to run
TypeError: Cannot read property 'bind' of undefined
at Runtime._createJestObjectFor (../../node_modules/.pnpm/jest@27.3.1/node_modules/jest/node_modules/jest-runtime/build/index.js:2193:46)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.619 s
Ran all test suites.
lerna ERR! pnpm run testonly exited 1 in '@accounts/oauth-twitter'
lerna WARN complete Waiting for 3 child processes to exit. CTRL-C to exit immediately.
ELIFECYCLE Command failed with exit code 1. Do you know what I'm missing, or should I not be trying to run the tests at this level? |
I never run the tests from the root of the monorepo so don't know about this error, you can run the testonly command in the subfolders too :) |
We can leave this to a separate pr, let's merge and release the work you did first :) |
Thanks for the work on this one and sorry it took so long! Will create a new release soon. |
Absolutely, happy to contribute! No issues with how long it took, it was over the year's end which is a busy time. |
This fix is related to this bug report: #1204
The configuration option of
convertSessionIdToMongoObjectId
was not being checked when using theidProvider
to create a new session.