mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #12536 from overleaf/em-oauth-refresh-tokens-index
Allow OAuth access tokens without refresh tokens GitOrigin-RevId: 5f95985b3a2e9b1c9a391b73476ce6b55875af87
This commit is contained in:
parent
25282f720e
commit
1f9cfd877a
1 changed files with 47 additions and 0 deletions
|
@ -0,0 +1,47 @@
|
||||||
|
const Helpers = require('./lib/helpers')
|
||||||
|
|
||||||
|
exports.tags = ['server-ce', 'server-pro', 'saas']
|
||||||
|
|
||||||
|
const OLD_INDEX = {
|
||||||
|
key: { refreshToken: 1 },
|
||||||
|
name: 'refreshToken_1',
|
||||||
|
unique: true,
|
||||||
|
}
|
||||||
|
const NEW_INDEX = {
|
||||||
|
key: { refreshToken: 1 },
|
||||||
|
name: 'refreshToken_1',
|
||||||
|
unique: true,
|
||||||
|
partialFilterExpression: { refreshToken: { $exists: true } },
|
||||||
|
}
|
||||||
|
const TMP_INDEX = {
|
||||||
|
key: { refreshToken: 1, dummyField: 1 },
|
||||||
|
name: 'refreshToken_tmp',
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.migrate = async client => {
|
||||||
|
const { db } = client
|
||||||
|
// Create a temporary index so that the refresh tokens are not left unindexed
|
||||||
|
// while we drop the index and recreate it.
|
||||||
|
await Helpers.addIndexesToCollection(db.oauthAccessTokens, [TMP_INDEX])
|
||||||
|
|
||||||
|
// Drop and recreate the index with different options
|
||||||
|
await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [OLD_INDEX])
|
||||||
|
await Helpers.addIndexesToCollection(db.oauthAccessTokens, [NEW_INDEX])
|
||||||
|
|
||||||
|
// Drop the temporary index
|
||||||
|
await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [TMP_INDEX])
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.rollback = async client => {
|
||||||
|
const { db } = client
|
||||||
|
// Create a temporary index so that the refresh tokens are not left unindexed
|
||||||
|
// while we drop the index and recreate it.
|
||||||
|
await Helpers.addIndexesToCollection(db.oauthAccessTokens, [TMP_INDEX])
|
||||||
|
|
||||||
|
// Drop and recreate the index with different options
|
||||||
|
await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [NEW_INDEX])
|
||||||
|
await Helpers.addIndexesToCollection(db.oauthAccessTokens, [OLD_INDEX])
|
||||||
|
|
||||||
|
// Drop the temporary index
|
||||||
|
await Helpers.dropIndexesFromCollection(db.oauthAccessTokens, [TMP_INDEX])
|
||||||
|
}
|
Loading…
Reference in a new issue