Skip to content

Commit

Permalink
Release 6.3.5: Propagate refresh option (#84)
Browse files Browse the repository at this point in the history
Propagate the refresh option to repository method when creating/updating/deleting documents.
  • Loading branch information
Aschen authored Jan 24, 2022
1 parent ae4b8e2 commit 65ef8c5
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 213 deletions.
15 changes: 11 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ class AuthenticationPlugin {
* @returns {Promise<object>}
*/
async create (request, credentials, kuid) {
const refresh = request.getString('refresh', 'wait_for');

if (!credentials.password) {
throw new this.context.errors.BadRequestError('Password needed.');
}
Expand All @@ -406,7 +408,7 @@ class AuthenticationPlugin {
pepper: false, // for future uses
encryption: this.config.encryption,
updater: request.context.user && request.context.user._id
}, {refresh: 'wait_for'});
}, { refresh });

return this.outputDocument(created);
}
Expand All @@ -418,6 +420,8 @@ class AuthenticationPlugin {
* @returns {Promise<object>}
*/
async update (request, credentials, kuid) {
const refresh = request.getString('refresh', 'wait_for');

if (credentials.kuid) {
throw new this.context.errors.BadRequestError('The request must not contain a kuid attribute.');
}
Expand Down Expand Up @@ -477,12 +481,13 @@ class AuthenticationPlugin {
delete newDocument.username;

updated = await this.getUsersRepository().create(newDocument);
await this.getUsersRepository().delete(oldDocumentId);
// wait for refresh only after the 2nd action
await this.getUsersRepository().delete(oldDocumentId, { refresh });
}
else {
await this.getUsersRepository().update(
Object.assign({_id: user._id}, credentialUpdate),
{refresh: 'wait_for'});
{ refresh });

updated = await this.getCredentialsFromUserId(kuid);
}
Expand All @@ -496,6 +501,8 @@ class AuthenticationPlugin {
* @returns {Promise<object>}
*/
async delete (request, kuid) {
const refresh = request.getString('refresh', 'wait_for');

const user = await this.getCredentialsFromUserId(kuid);

await this.passwordRequiredCheck(request, user);
Expand All @@ -504,7 +511,7 @@ class AuthenticationPlugin {
throw new this.context.errors.PreconditionError(`No credentials found for user "${kuid}".`);
}

return this.getUsersRepository().delete(user._id, {refresh: 'wait_for'});
return this.getUsersRepository().delete(user._id, { refresh });
}

/**
Expand Down
Loading

0 comments on commit 65ef8c5

Please sign in to comment.